版主的小弟也很牛叉啊!
public static void main(String[] args) throws IOException {
// 根据字符的ASCII查找
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringBuffer sb = new StringBuffer();
sb.append(str);
int a = 0, b = 0, c = 0;
for (int j = 0; j < sb.length(); j++) {
//48——57代表0——9
if (sb.charAt(j) <= 57 & sb.charAt(j) >= 48) {
a++;
}
//65——90代表A-Z,97-122代表a——z
if (sb.charAt(j) <= 90 & sb.charAt(j) >= 65 | sb.charAt(j) <= 122
& sb.charAt(j) >= 97) {
b++;
}
if (sb.charAt(j) == ' ') {
c++;
}
}
System.out.println("数字个数:" + a);
System.out.println("字母数:" + b);
System.out.println("空格数:" + c);
System.out.println("其他字符数:" + (sb.length() - a - b - c));
}
|