输入一个字符串,用for循环语句读出该字符串。统计其中大写字母的个数,小写字母的个数,以及其他字符的个

RT 很急用C#语言
2025-03-07 05:13:53
推荐回答(2个)
回答1:

public string GetString(string str)
{
int A = 0;
int a = 0;
int x = 0;
for (int i = 0; i < str.Length; i++)
{
int t = (int)str[i];
if (t >= 65 && t <= 90)
A++;
else if (t >= 97 && t <= 122)
a++;
else
x++;
}
return string.Format("大写字母的个数:{0}个;小写字母的个数:{1}个;其它字符的个数:{2}个;", A, a, x);
}

回答2:

#!python
import string
meter = {'upper':0, 'lower':0, 'other':0}
for a in st:
type = 'upper' if a in string.uppercase else (
'lower' if a in string.lowercase else 'other')
meter['type'] += 1