import java.util.*;
class MapTest3
{
public static void main(String[] args)
{
String s=charCount("dsahdjajdfdfgdh");
System.out.println("s");
}
public static String charCount(String str)//接受字符串
{
char[] chs=str.toCharArray();//这里是怎么理解啊????
TreeMap<Character,Integer> tm=new TreeMap<Character,Integer>();//Character换成String行吗??
for (int x=0;x<chs.length ;x++ )
{
Integer value=tm.get(chs[x]);//通过键获取值
if (value==null)
{
tm.put(chs[x],1);
}
else
{
value = value+1;
tm.put(chs[],value);//怎么出错了啊 ???
}
}
StringBuilder sb=new StringBuilder();//都什么时候应用这个缓冲区啊??
Set<Map.Entry<Character,Integer>> entrySet=tm.entrySet();
Iterator<Map.Entry<Character,Integer>> it=entrySet.it.iterator();
while (it.hasNext())
{
Map.Entry<Character,Integer>me=it.next();
Character ch=me.getKey();
Integer value=me.getValue();
sb.append(ch+"("+value+")");
}
return sb.toString();//这里为什么不返回sb啊?
}
}
错误
MapTest3.java:56: 需要 ".class"
tm.put(chs[],value);
^
1 错误
|