日期:2014-05-20  浏览次数:20730 次

Java字符统计问题
左边一个带滚动条的文本框,
输入英文字幕。
中间一个按钮,
右边统计每一个字母的个数。

------解决方案--------------------
没明白
------解决方案--------------------
你要在什么地方实现?基本上明白你的意思了
------解决方案--------------------
不要搞得像布置作业一样。。。
------解决方案--------------------
public class 字母个数
{

public static void main(String[] fdfd)
{
sum( "asdASDasd&*( ");
}

static void sum(String str)
{
HashMap hash = new HashMap();

for(int i = 0;i < str.length();i++)
{
if(hash.containsKey(str.charAt(i)))
{
hash.put(str.charAt(i),(Integer)hash.get(str.charAt(i))+1);
}
else
{
hash.put(str.charAt(i),1);
}
}

for (Iterator it = hash.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
System.out.println(entry.getKey()+ "--------- "+entry.getValue());

}
}
}


S---------1
d---------2
D---------1
A---------1
a---------2
s---------2


简单写了个方法,顺序暂时不能排
你就参考一下吧
高手不要笑