Write a program in C# Sharp to display the characters and frequency of character from giving string

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to display the characters and frequency of character from giving string. 
Test Data:
Input the string: apple
Expected Output:
The frequency of the characters are :
Character a: 1 times
Character p: 2 times
Character l: 1 times
Character e: 1 times

الأجوبة

using System;
using System.Linq;
using System.Collections.Generic;
class LinqExercise5
{
    static void Main(string[] args)
    {
      string str; 
            Console.Write("\nLINQ : Display the characters and frequency of character from giving string : "); 
            Console.Write("\n----------------------------------------------------------------------------\n");	
            Console.Write("Input the string : ");
            str= Console.ReadLine();
            Console.Write("\n");       
            var FreQ = from x in str  
                    group x by x into y  
                    select y;  
                Console.Write("The frequency of the characters are :\n");
                foreach(var ArrEle in FreQ)  
                    {  
                    Console.WriteLine("Character "+ArrEle.Key + ": " + ArrEle.Count()+" times");  
                    }  
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...