题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int y = 0, k = 0, shu = 0, el = 0; while (sc.hasNext()) { String s = sc.nextLine(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') { y++; } else if (c >= '0' && c <= '9') { shu++; } else if (c == ' ') { k++; } else { el++; } } System.out.println(y); System.out.println(k); System.out.println(shu); System.out.println(el); } } }