Java实现找出数组中重复次数最多的元素以及个数
生活随笔
收集整理的這篇文章主要介紹了
Java实现找出数组中重复次数最多的元素以及个数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/**數(shù)組中元素重復(fù)最多的數(shù)* @param array* @author shaobn* @param array*/public static void getMethod_4(int[] array){Map<Integer, Integer> map = new HashMap<>();int count = 0;int count_2 = 0;int temp = 0;for(int i=0;i<array.length;i=i+count){if(i==array.length-1){temp =1;break;}for(int j=i+1;j<array.length;j++){if(array[i]==array[j]){count++;}continue;}if(count>count_2){count_2 = count;map.put(count_2, array[i]);}}System.out.println(map.get(count_2));}
int[] array = {1,1,1,5,5,8,9}
int[] array = {1,1,1,5,5,8,9}
?
轉(zhuǎn)載于:https://www.cnblogs.com/assassin666/p/5903448.html
總結(jié)
以上是生活随笔為你收集整理的Java实现找出数组中重复次数最多的元素以及个数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 网络传输 中文乱码问题
- 下一篇: 单例Singleton