Hi frnds...
My qstn:Accept a string from the user and display which character is repeated most. using Console App....
I've tried but strucked.....while printing
Pls rectrify and in my method it return all characters repeated with N times i need the 1 char which occus most times
static void Main(string[] args)
{
string str;
Console.WriteLine("\nEnter the String:");
str= Console.ReadLine();
char[] chars = str.ToCharArray();
List<char> charList = new List<char>();
Console.WriteLine("\nThe entered string is:" + str);
for (int i = 0; i <chars.Length; i++)
{
if (!charList.Contains(chars[i]))
{
charList.Add(chars[i]);
}
}
foreach (char c in charList)
{
int Count = CountChar(str, c);
}
}
private static int CountChar(string Inp, char c)
{
int retVal = 0;
for (int i = 0; i < Inp.Length; i++)
{
if (c == Inp[i])
{
retVal++;
}
}
return retVal;
}
Join Hands Change lives
Thanks & Regards
Straight Edge Society