import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Text04 {
public static void main(String[] args) {
Map<Character,Integer> mapping = new HashMap<Character, Integer>();
System.out.println("请输入一个字符串:");
Scanner sc = new Scanner(System.in);
String rs = sc.nextLine();
char[] cs = rs.toCharArray();
for (int i = 0; i < cs.length; i++) {
if (mapping.containsKey(cs[i])) {
mapping.put(cs[i], mapping.get(cs[i])+1);
}else{
mapping.put(cs[i], 1);
}
}
Set<Character> keySet = mapping.keySet();
for (Character character : keySet) {
System.out.print(character+"("+mapping.get(character)+")"+" ");
}
}
}
|
|