问题描述
有谁愿意帮帮我吗,感谢大侠
解决方案
/** * @param args */public static void main(String[] args) throws Exception {String contents = "Hello World";char[] content = contents.toCharArray();Map<Character, Integer> map = new HashMap<Character, Integer>();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);elsemap.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);}
时间: 2025-01-29 15:11:33