思路:这题还是比较简单的,直接遍历判断即可
public static void main(String[] args) { int strCount = 0; int blankCount = 0; int numCount = 0; int otherCount = 0; Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ String str = scanner.nextLine(); char[] chars = str.toCharArray(); for (char c : chars) { if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')){ strCount++; } else if(c == ' '){ blankCount++; } else if((c >= '0' && c <= '9')){ numCount++; } else { otherCount++; } } System.out.println(strCount); System.out.println(blankCount); System.out.println(numCount); System.out.println(otherCount); } }