//输入一串字符,判断英文字母,空格,数字及其他字符的个数
public static void checkString(String str){
int countNum = 0;
int countStr = 0;
int countKG = 0;
int countElse = 0;
int countHZ = 0;
char[] c = str.toCharArray();
String[] arrStr = new String[c.length];
for (int i = 0; i < c.length; i++) {
arrStr[i] = String.valueOf(c[i]);
}
for (String i : arrStr) {
if(i.matches("[0-9]")){
countNum++;
}else if(i.matches("[a-zA-Z]")){
countStr++;
}else if(i.matches("\\p{Blank}")){
countKG++;
}else if(i.matches("[\u4e00-\u9fa5]")){
countHZ++;
}else{
countElse++;
}
}
System.out.println("数字个数:"+countNum+",英文字母个数:"+countStr+",空格:"+countKG+",汉 字:"+countHZ+",其他:"+countElse);
}
public static void checkString(String str){
int countNum = 0;
int countStr = 0;
int countKG = 0;
int countElse = 0;
int countHZ = 0;
char[] c = str.toCharArray();
String[] arrStr = new String[c.length];
for (int i = 0; i < c.length; i++) {
arrStr[i] = String.valueOf(c[i]);
}
for (String i : arrStr) {
if(i.matches("[0-9]")){
countNum++;
}else if(i.matches("[a-zA-Z]")){
countStr++;
}else if(i.matches("\\p{Blank}")){
countKG++;
}else if(i.matches("[\u4e00-\u9fa5]")){
countHZ++;
}else{
countElse++;
}
}
System.out.println("数字个数:"+countNum+",英文字母个数:"+countStr+",空格:"+countKG+",汉 字:"+countHZ+",其他:"+countElse);
}