如果一串字符如"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("....");
}
}
