//计算字符串中大写字母,小写字母,数字,其他字符的数目
public class Demo6 {
public static void main(String[] args) {
String sc = "jjjjjkJJJKKJ898765*&^%$#";
char[] s = sc.toCharArray();
int uppercase = 0;
int lowercase = 0;
int num = 0;
int other = 0;
for (int i = 0; i < s.length; i++) {
if (s[i] >= 'A'&& s[i] <= 'Z') {
uppercase++;
}
else if (s[i] >= 'a' && s[i] <= 'z') {
lowercase++;
}
else if (s[i] >= '0' && s[i] <= '9') {
num++;
}
else{
other++;
}
}
System.out.println("大写字母有" + uppercase +"个");
System.out.println("小写字母有" + lowercase +"个");
System.out.println("数字有" + num +"个");
System.out.println("其他字符有" + other +"个");
}
}
|
|