public static void main(String[] args) {
int numberCount = 0;
int smallCount = 0;
int bigCounnt = 0;
int other = 0;
Scanner sc = new Scanner(System.in);
String str = sc.next();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
System.out.println(c);
if (c >= 'a' && c <= 'z') {
smallCount++;
} else if (c >= 'A' && c <= 'z') {
bigCounnt++;
} else if (c >= '0' && c <= '9') {
numberCount++;
} else {
other++;
}
}
System.out.println("数字有:" + numberCount + "个");
System.out.println("大写字母有:" + bigCounnt + "个");
System.out.println("小写字母有:" + smallCount + "个");
System.out.println("其他字符有:" + other + "个");
}
统计字符串
最新推荐文章于 2024-09-02 22:33:56 发布