public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请您输入一个字符串:");
HashMap<String, Integer> hm = new HashMap<>();
String line = sc.nextLine();
char[] arr = line.toCharArray();
for (char c : arr) {
hm.put(c, hm.containsKey(c) ? hm.get(c) + 1 : 1);//谁能说说这行代码哪里错了
}
for (String key : hm.keySet()) {
Integer value = hm.get(key);
System.out.println(key + "=" + value);
}
}
|
|