import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Text03 {
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++) {
int count = 0;
for (int j = 0; j < cs.length; j++) {
if (cs[i]==cs[j]) {
count++;
}
}
mapping.put(cs[i], count);
}
Set<Character> keySet = mapping.keySet();
for (Character character : keySet) {
System.out.print(character+"("+mapping.get(character)+")"+" ");
} |
|