首页 > 其他 > 详细

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

时间:2020-02-26 11:27:12      阅读:72      评论:0      收藏:0      [点我收藏+]
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 +"个 ");
    }

}

 

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

原文:https://www.cnblogs.com/yxfyg/p/12365642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!