public class CountStr{
public static void main(String[] args) {
System.out.println(getStrCount(getStr()));
}
public static String getStr(){
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要统计字符数量的字符串:");
return scanner.next();
}
public static HashMap<Character, Integer> getStrCount(String str){
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < str.length(); i++){
map.merge(str.charAt(i), 1, Integer::sum);
}
return map;
}
}