public class StringTest {
public static void main(String[] args) {
// 封装键盘录入数据
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String line = sc.nextLine();
// 定义统计变量
int big = 0;
int small = 0;
int number = 0;
// length,charAt
for (int x = 0; x < line.length(); x++) {
// 获取每一个字符
char ch = line.charAt(x);
if (ch >= '0' && ch <= '9') {
number++;
} else if (ch >= 'A' && ch <= 'Z') {
big++;
} else if (ch >= 'a' && ch <= 'z') {
small++;
}
}
System.out.println("字符串中大写字母出现次数是:"+big);
System.out.println("字符串中小写字母出现次数是:"+small);
System.out.println("字符串中数字出现次数是:"+number);
}
}