题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str = sc.nextLine();
//字母个数
int l = 0;
//空格个数
int sp = 0;
//数字个数
int d = 0;
//其他字符个数
int o = 0;
for(int i=0;i<str.length();i++){
char c = str.charAt(i);
if(Character.isLetter(c)){
l++;
}else if(Character.isSpaceChar(c)){
sp++;
}else if(Character.isDigit(c)){
d++;
}else{
o++;
}
}
System.out.println(l);
System.out.println(sp);
System.out.println(d);
System.out.println(o);
}
}
}