public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("请输入");
TreeMap<Character, Integer> tm = new TreeMap<>();
String s = sc.nextLine();
char[] arr = s.toCharArray();
for (char c : arr) {
if (!tm.containsKey(c)) {
tm.put(c, 1);
} else {
tm.put(c, tm.get(c) + 1);
}
}
for (char c : tm.keySet()) {
System.out.println(c+" "+tm.get(c));
}
}
}
public boolean containsKey(Object key) {
return getEntry(key) != null;
}
public V get(Object key) {
if (key == null)
return getForNullKey();
Entry<K,V> entry = getEntry(key);
return null == entry ? null : entry.getValue();
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |