System.out.println("請輸入壹個字符串");
String line = sc.next();
HashMap<Character, Integer> hm = new HashMap<>();
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
hm.put(c, hm.containsKey(c)?hm.get(c)+1:1);
}
for (Character c : hm.keySet()) {
System.out.print(c+":"+hm.get(c)+"次"+" ");
//aaAAArer2344
// 測試結果 3:1次 2:1次 e:1次 r:2次 A:3次 4:2次 a:2次
}
}
}