`public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串中的大写字母,小写字母,数字都可以");
String s = sc.next();
count(s);

}

public static void count(String s) {
    char[] chars = s.toCharArray();
    int da = 0;
    int xiao = 0;
    int shu = 0;
    for (int i = 0; i < chars.length; i++) {
        if ('A' <= chars[i] && chars[i] <= 'Z') {
            da++;
        } else if ('a' <= chars[i] && chars[i] <= 'z') {
            xiao++;
        } else if ('0' <= chars[i] && '9' >= chars[i]) {
            shu++;
        }
    }
    System.out.println("大写字母数量:" + da);
    System.out.println("小写字母数量:" + xiao);
    System.out.println("数字数量:" + shu);

}

}`

posted on 2020-12-15 09:22  Wang梦怡  阅读(410)  评论(0编辑  收藏  举报