/*
	 * 得到字符出现次数最多的字符
	 */
	public static void getMaxMinChar(String str) {
		Map<Character, Integer> map = new TreeMap<Character, Integer>();
		for (int i = 0; i < str.length(); i++) {
			if (map.containsKey(str.charAt(i))) {
				map.put(str.charAt(i), map.get(str.charAt(i)) + 1);
			} else {
				map.put(str.charAt(i), 1);
			}
		}
		char maxchar = ' ';
		int maxnum = 0;
		for (char c : map.keySet()) {
			if (map.get(c) > maxnum) {
				maxnum = map.get(c);
				maxchar = c;
			}
		}
		System.out.print("出现次数最到的字符:" + maxchar + "   出现次数=" + maxnum);
	}

 

评论
发表评论

您还没有登录,请登录后发表评论

LEICHAO
搜索本博客
我的相册
A685826d-c23b-32fa-ad99-59caf41ba18a-thumb
prototype_ajax
共 2 张
存档
最新评论