import java.util.Scanner;
/**
* Author: 明明就会被淘汰
* Date: 2022/1/22 上午1:51
* Title: 统计字符串的案例
*/
public class 统计字符串的案例 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入字符串:");
String input = scanner.nextLine();
int bigCount = 0;
int smallCount = 0;
int numberCount = 0;
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c >= 'A' && c <= 'Z') {
bigCount++;
} else if (c >= 'a' && c <= 'z') {
smallCount++;
} else if (c >= '0' && c <= '9') {
numberCount++;
}
}
System.out.println("大写的有:" + bigCount + "个");
System.out.println("小写的有:" + smallCount + "个");
System.out.println("数字的有:" + numberCount + "个");
}
}
版权属于:
肚子饿了才有力气吃饭
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论 (0)