有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数。
如果一串字符如"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("....");
}
}
魔由心生,有万境纵横,无一道清静,无量寿佛!
浙公网安备 33010602011771号