package cn.edu.hust.divisor;
import java.util.Scanner;
public class ReadChar {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String str = stdin.nextLine();
new ReadChar().statString(str);
}
public void statString(String str) {
int strNum = 0;// 英文字符的个数
int spaceNum = 0;// 空格的个数
int numsNum = 0;// 数字的个数
int otherNum = 0;// 其他的个数
for (int index = 0; index < str.length(); index++) {
int num = (int) str.charAt(index);
if ((num >= 97 && num <= 122) || (num >= 65 && num <= 90)) {
strNum++;
} else if ((num >= 48 && num <= 57)) {
numsNum++;
} else if (num == 32) {
spaceNum++;
} else {
otherNum++;
}
}
{
System.out.println("您所输入的字符串为:" + str);
System.out.println("此字符串有英文字符:" + strNum + "个");
System.out.println("此字符串有数字:" + numsNum + "个");
System.out.println("此字符串有空格:" + spaceNum + "个");
System.out.println("此字符串有其他字符:" + otherNum + "个");
}
}
}