import java.util.*;
import java.util.Map.Entry;
public class Demo1
{
public static void main(String[] args)
{
charCount("cfgd5ZI001KJIUYUGLKOLUIHUIUIHUIUIUIUI545455450111drtsaaa");
}
public static void charCount(String str)
{
char[] chs=str.toCharArray();
TreeMap<Character,Integer> tp=new TreeMap<Character, Integer>();
for(int x=0;x<chs.length;x++)
{
if(!(chs[x]>='a'&&chs[x]<='z'||chs[x]>='A'&&chs[x]<='Z'||chs[x]>=0&&chs[x]<=9))
//throw new RuntimeException("出现非法字符");
continue;
Integer value=tp.get(chs[x]);
if(value!=null)
{
tp.put(chs[x], 1);
}
else
{
value=value+1;
tp.put(chs[x], value);
}
}
//System.out.println(tp.get('p'));
Set<Map.Entry<Character,Integer>> entryset=tp.entrySet();
Iterator<Entry<Character, Integer>> it=entryset.iterator();
while(it.hasNext())
{
Map.Entry<Character, Integer> me=it.next();
Character key=me.getKey();
Integer value=me.getValue();
System.out.print(key+"("+value+")");
}
}
}
请帮我看一哈 哪里的问题???跪谢。。。
|