public class Sum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int a=0,b=0,c=0,d=0;
char ch[] = s.toCharArray();
int i=0;
for(;i<ch.length;i++) {
if((ch[i]>='a' && ch[i]<='z')||(ch[i]>='A'&&ch[i]<='Z'))
a++;
else if(ch[i]==' ')
b++;
else if(ch[i]>='0' && ch[i]<='9')
c++;
else
d++;
}
System.out.println("英文字母:"+a+"\n空格:"+b+"\n数字"+c+"\n其他字符:"+d);
}
}
02-02
1170
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)