首页 > 编程语言 > 详细

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

时间:2016-09-24 17:42:29      阅读:713      评论:0      收藏:0      [点我收藏+]
/**数组中元素重复最多的数
     * @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}

 

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

原文:http://www.cnblogs.com/assassin666/p/5903448.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!