import java.security.Key;标签:字符,java,i1,个数,System,tm,字符串,import,append From: https://www.cnblogs.com/zhaoshengfu/p/18079029
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class Main {
public static <scanner> void main(String[] args) {
System.out.println("请输入一个字符串");
Scanner sc = new Scanner(System.in);
String S = sc.next();
TreeMap<Character, Integer> tm = new TreeMap<Character, Integer>();
for (int i = 0; i < S.length(); i++) {
char c = S.charAt(i);
Integer i1 = tm.get(c);
if (i1 == null) {
tm.put(c, 1);
} else {
i1++;
tm.put(c, i1);
}
}
StringBuilder stringBuilder = new StringBuilder();
Set<Character> characters = tm.keySet();
for (char c : characters) {
int m = tm.get(c);
stringBuilder.append(c).append("(").append(m).append(")");
}
String string = stringBuilder.toString();
System.out.println(string);
}
}