import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class Deom01_TreeMap {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请您输入一个字符串:");
String line = scan.nextLine();
char[] ch = line.toCharArray();
TreeMap<Character, Integer> tm = new TreeMap<Character,Integer>();
for (char c : ch) {
Integer i = tm.get(c);
if(i=null){
tm.put(c, 1);
}else{
Integer in = tm.get(c)+1;
tm.put(c, in);
}
}
Set<Character> key = tm.keySet();
for (Character c : key) {
Integer integer = tm.get(c);
System.out.println(c + "====" + integer);
}
}
}
请问这段代码有什么问题呢?找了好久都没有找到,求大神看看 |
|