Maximum times repeated character

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace MaxRepeatedCharacters
{
class Program
{
static void Main(string[] args)
{
int max = 0;

Console.WriteLine("Enter the string");
string str = Console.ReadLine();

char maxRepeatedCharacter = str[0];

if (str == "")
{
Console.WriteLine("String is empty");
Console.ReadLine();
return;
}

Hashtable hash = new Hashtable();

foreach(char ch in str)
{
if (hash.ContainsKey(ch))
{
hash[ch] = (int)hash[ch] + 1;

if ((int)hash[ch] > max)
{
maxRepeatedCharacter = ch;
max = (int)hash[ch];
}
}
else
{
hash.Add(ch, 1);
}
}

Console.WriteLine("Max repeated character is: " + Convert.ToString(maxRepeatedCharacter));
Console.ReadLine();

}
}
}

Comments

Popular posts from this blog

Network Security: LAN manager authentication level

Cisco AnyConnect Secure Mobility Client - VPN service not available. The VPN agent service is not responding