import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("输入字符:");
String c= scanner.nextLine();
char[] str=c.toCharArray();
int abc,blank,num,other;
abc=blank=num=other=0;
for (int i = 0; i < str.length; i++){
if(str[i]>='A'&&str[i]<='z')
abc++;
else if(str[i]>='0'&&str[i]<='9')
num++;
else if(str[i]==' ')
blank++;
else
other++;
}
System.out.println("这段字符串中英文字母:"+abc+"个,空格:"+blank+"个,数字:"+num+"个,其他字符:"+other+"个。");
}
}
示例输出