有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数。

如果一串字符如"aaaabbc中国1512"要分别统计英文字符的数量,中文字符的数量,和数字字符的数量,

假设字符中没有中文字符、英文字符、数字字符之外的其他特殊字符。

package com.aspire.test;

public class Test {
    public static void main(String[] args) {
        
        String str = "aaaabbc中国1512";
        int engishCount = 0;
        int chineseCount = 0;
        int digitCount = 0;
        for(int i=0;i<str.length();i++)
        {
            char ch = str.charAt(i);
            if(ch>='0' && ch<='9')
            {
                digitCount++;
            }
            else if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
            {
                engishCount++;
            }
            else
            {
                chineseCount++;
            }
        }
        System.out.println("....");

    }
}

  

posted on 2017-03-22 09:26  我是齐欢  阅读(3975)  评论(1编辑  收藏  举报