package cn.itcast_03;import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class 统计字符串中每个字符的出现字数 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个字符串");String line = sc.nextLine();TreeMap<Character,Integer> tm = new TreeMap<Character,Integer>();char[] chs = line.toCharArray(); for(char ch:chs) {Integer i = tm.get(ch);if(i == null) {tm.put(ch, 1);}else {i++;tm.put(ch, i);}}StringBuilder sb = new StringBuilder();Set<Character> set = tm.keySet(); for(Character key:set) {Integer value = tm.get(key);sb.append(key).append("(").append(value).append(")");}String s = sb.toString();System.out.println(s);}
}