harish reddy

harish reddy

  • NA
  • 162
  • 30.4k

Alphabets counts

Apr 9 2018 12:35 AM
//Write a program that reads a string from the console and prints in alphabetical order all letters from the input string and how many times each one of them occurs in the string.
 
Pls help i amnot getting output 
string text = "dadda";
char[] newarray = text.ToArray();
Array.Sort(newarray); int count = 1;
foreach (var item in newarray)
{
Console.WriteLine(item);
}
for (int i = 0; i < text.Length; i++)
{
for (int j = i + 1; j >= i; j++)
{
if (text[i] == text[j])
{
count++;
}
} Console.WriteLine("{0} appears {1} times", text[i], count);
}
 
My expected output is :
 
d appears 3 times
a appears 2 times.
 

Answers (5)