这也是面试题
public static void strNumber(String str) {
int z = 0;
int k = 0;
int g = 0;
int f = 0;
//byte化
byte buf[] = str.getBytes();
for (int i = 0; i < str.length(); i++) {
if (buf[i] == ' ') {
z++;
}else if ((buf[i] >= '0') && (buf[i] <= '9')) {
k++;
}else if (((buf[i] >= 'a') && (buf[i] <= 'z')) || ((buf[i] >= 'A') && (buf[i] <= 'Z'))) {
g++;
}else{
f++;
}
}
System.out.println("空格数是" + z);
System.out.println("数字个数" + k);
System.out.println("字母个数" + g);
System.out.println("其他个数" + f);
}
public static void main(String[] args) {
strNumber("kkk111 hhh hhh99 &&");
}