//统计大写字符,小写字符,数字字符
public class testString {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String str = sc.next();
int big_count = 0;
int small_count = 0;
int number_count = 0;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(c >= 'a' && c <= 'z'){
small_count ++;
}
if(c >= 'A' && c <='Z'){
big_count ++;
}
if(c >= '0' && c <= '9'){
number_count ++;
}
}
System.out.println("大写字符数量为:" + big_count);
System.out.println("小写字符数量为:" + small_count);
System.out.println("数字字符数量为:" + number_count);
}
}
运行结果:
