import Java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
public class TestStringSplict {
public static void main(String[] args){
String str = "aaaaaaaccccccccccccccccccccccaaaabb";
// 用map实现
// TreeMap<Character,Integer> map = new TreeMap<Character,Integer>();
// for(Character ch : str.toCharArray()){
// if((ch>='a' && ch<'z')||(ch>'A' && ch<'Z')){
// Integer count = map.get(ch);
// map.put(ch, null==count?1:count+1);
// }
// }
//
// System.out.println(Collections.max(map.values()));
//用普通数组实现
int[] aa = new int[60];
for(char temp:str.toCharArray()){
if((temp>=65 && temp<=90)||(temp>=97 && temp<=122)){
temp -= 65;
aa[temp]++;
}
}
int max = aa[0]; int position = 0;
for(int i=0;i<aa.length;i++){
if(aa[i]>max){
max = aa[i]; position = i;
}
}
System.out.println(max);
System.out.println("字母"+(char)(position+65) + "出现" + max + "次");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有