@Test
//输入一行字符,分别统计其英文大小写字母,数字,其他字符
public void test15(){
// String str = "45zxcASD *&…^%234";//字符串
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一行字符串:");
// String str = scanner.next();//缺点是不能读入空格
String str = scanner.nextLine();//可以读入空格了
System.out.println(str);
char[] chars = str.toCharArray();//把字符串转换成字符数组[4, 5, z, x, c, A, S, D, , *, &, …, ^, %, 2, 3, 4]
int countCapitalLetter = 0;
int countSmallLetter = 0;
int countNum = 0;
int countOther = 0;
for (int i = 0; i < chars.length; i++) {
if(chars[i] >= 'A' && chars[i] <='Z'){
countCapitalLetter++;
}else if(chars[i] >= 'a' && chars[i] <= 'z'){
countSmallLetter++;
}else if(chars[i] >= '0' && chars[i] <= '9'){
countNum++;
}else{
countOther++;
}
}
System.out.println("大写字母个数:" +countCapitalLetter);
System.out.println("小写字母个数:" +countSmallLetter);
System.out.println("数字个数:" +countNum);
System.out.println("其他字符个数:" +countOther);
}