Java实现找出数组中重复次数最多的元素以及个数


/**数组中元素重复最多的数
     * @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}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM