在控制台输入一串英文字符串,要求统计小写字母和大写字母出现的次数!

例:输入了AbcDEfg 小写:4 大写:3,还有就是用C#语言!

public static void Main(string[] args)
{
string instr = Console.ReadLine();
int dx = 0;
int xx = 0;
foreach (char c in instr)
{
if (c >= 'A' && c <= 'Z')
{
dx++;
}
else if (c >= 'a' && c <= 'z')
{
xx++;
}
}
Console.WriteLine("大写字母{%d}个小写字母{%d}个", dx, xx);
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答