String s2 = "ABCDEFabcdef12345!@#$%";
int big = 0;
int small = 0;
int num = 0;
int other = 0;
for (int i = 0; i < s2.length(); i++) {
char c = s2.charAt(i);
if (c >= 'A'&& c <= 'Z') {
big++;
}else if (c >= 'a'&& c <= 'z') {
small++;
}else if (c >= '0'&& c <= '9') {
num++;
}else {
other++;
}
}
System.out.println(s2+"中的大写字母有"+big+"个,小写字母有"+small+"个,数字有"
+num+"个,其他符号有 "+other);
}
仅供参考 |