题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
int letter = 0;
int space = 0;
int digit = 0;
int other = 0;
for (char c : line.toCharArray()) {
if (Character.isLetter(c)) {
letter++;
} else if (Character.isSpaceChar(c)) {
space++;
} else if (Character.isDigit(c)) {
digit++;
} else {
other++;
}
}
System.out.println(letter);
System.out.println(space);
System.out.println(digit);
System.out.println(other);
}
}