统计字符串中各种字符的个数

public class ClassfiedChar{
    
    public static void main(String[] args){
        
        String str = "ahGJ;j:NLKn;[][]mpon;l()mp'mUIGGUILB";
        char[] array = str.toCharArray();
        int up = 0;
        int low = 0;
        int other = 0;
        
        for(int i=0;i<str.length();i++){
            if('A' <= array[i] && array[i] <= 'Z'){
                up++;
            } else if('a' <= array[i] && array[i] <= 'z'){
                low++;
            } else {
                other++;
            }
        }
        
        System.out.println("大写字母" + up + "个 " + "小写字母" + low + "个 " +"其他字符" + other +"个 ");
    }

}

 

posted @ 2020-02-26 10:48  yxfyg  阅读(704)  评论(0)    收藏  举报