题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
char[] ch=sc.nextLine().toCharArray();
int count1=0;
int count2=0;
int count3=0;
for (int i = 0; i < ch.length; i++) {
if((ch[i]>='A' && ch[i]<='Z') || (ch[i]>='a' && ch[i]<='z'))
count1++;
else if(ch[i]==' ')
count2++;
else if(ch[i]>='0' && ch[i]<='9')
count3++;
}
System.out.println(count1);
System.out.println(count2);
System.out.println(count3);
System.out.println(ch.length-count1-count2-count3);
}
sc.close();
}
}