class Program
{
static void Main(string[] args)
{
string value = "abadadgesadsfg";
Console.WriteLine(getMaxChar(value).ToString());
}
public static string getMaxChar(String value)
{
string maxChar = "";
int maxIndex = 0;
for (int i = 0; i < value.Length; i++)
{
string tempchar = value.Substring(i,1);
int tempIndex = 0;
for (int j = 0; j < value.Length - i; j++)
{
if (tempchar == value.Substring(j,1))
{
tempIndex++;
}
}
if (tempIndex > maxIndex)
{
maxIndex = tempIndex;
maxChar = tempchar;
}
}
return maxChar;
}
}
选出字符串中出现次数最多的字符
最新推荐文章于 2022-07-28 15:53:28 发布