eg:a[]={11,44,55,22,44,44,33}
最大重复数是44,重复的个数是3
最大重复数是44,重复的个数是3
解决方案 »
- Eclipse中怎么加 spring ide?
- jbpm
- java中有没有消息机制?
- IE OLE技术 如何判断一个请求已经全部完成
- 父类调用了子类的方法???
- 求超级玛丽游戏素材
- hql语句书写 方法"from Comment c where c.assetId='"+assetId+"' and c.status='"+status+"
- 有没有统一的录入界面???
- 谁有sqlserver7.0的驱动,急用!!!
- 请问,我用String str2 = new String(rs.getString(2).getBytes("ISO8859_1"),"gb2312");为什么总抱错啊??
- 正则表达式表达字符串中出现‘张“或”涨“
- 关于垃圾回收的一个问题
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class TestCy {
public static Map getInt(int[] a) {
Map map = new HashMap(); for (int i = 0; i < a.length ; i++) {
if (map.get(a[i]) == null) {
map.put(a[i], 1);
} else {
map.put(a[i], ((Integer) map.get(a[i])) + 1);
}
}
return map;
}
public static void test(int[] a){
Map map = getInt(a);
Object[] arr = map.values().toArray();
Arrays.sort(arr);
Iterator iterator= map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry entry = (Map.Entry)iterator.next();
if(entry.getValue()==arr[arr.length-1]){
System.out.println(entry.getKey().toString()+"---"+arr[arr.length-1]);
}
}
}
public static void main(String[] args) {
int a[]={11,44,55,22,44,44,33};
test(a); }
}
public class Test{
public static void main (String[] args) {
int a[]={11,44,55,22,44,44,33};
Arrays.sort(a);
int i=a.length-1;
int j=a.length-2;
while(j>=0&&a[i]!=a[j]){
i--;j--;
}
if(j>=0){
while(j>=0&&a[i]==a[j]) j--;
System.out.println("最大的有重复的数是:"+a[i]+" 重复的次数是:"+(i-j));
}else{
System.out.println("不存在重复的数!");
}
}}