有谁愿意帮帮我吗,感谢大侠
1条回答 默认 最新
gxl1989225 2012-12-18 17:46关注[code="java"]
/**
* @param args
*/
public static void main(String[] args) throws Exception
{
String contents = "Hello World";
char[] content = contents.toCharArray();
Map map = new HashMap();
for(int i = 0; i < content.length; i ++)
if(-1 != contents.indexOf(content[i]))
if(null != map.get(content[i]))
map.put(content[i], map.get(content[i]) + 1);
else
map.put(content[i], 1);int maxValue = map.get(content[0]); char str = ' '; for(int j = 0; j < content.length; j ++) if(maxValue < map.get(content[j])) { maxValue = map.get(content[j]); str = content[j]; } System.out.println("现次数最多的字符:" + str + " 出现次数:" + maxValue); }[/code]
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1