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);
}
}