标签:imp static class hashmap str param contain rac out
package Test;
import java.util.HashMap;
import java.util.Map;
public class test3 {
/**
* 计算"aabbc"中最多的相同字母数
* @param args
*/
public static void main(String[] args) {
String str="aabbbcc";
char arr[]=str.toCharArray();
Map<Character,Integer> map=new HashMap<Character,Integer>();
for (char c : arr) {
if(map.containsKey(c)){
map.put(c, (Integer)map.get(c)+1);
}else{
map.put(c, 1);
}
}
int max=0;
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
if(max<entry.getValue()){
max=entry.getValue();
}
}
System.out.println("最多相同字母数"+max);
}
}
标签:imp static class hashmap str param contain rac out
原文地址:https://www.cnblogs.com/v-lcc/p/9697031.html