java-String-统计字符串的案例

java-String-统计字符串的案例

肚子饿了才有力气吃饭
2022-01-22 / 0 评论 / 2 阅读 / 正在检测是否收录...
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 + "个");
    }
}
0

评论 (0)

取消