Write a Program to FInd Repeated Numbers Count in an Array using Java

import java.util.HashMap;
import java.util.Map;


public class DuplicateNumbersCount {

    /**
     * @param args
     */
    public static void main(String[] args) {
       
         int numArr[] = {3,6,5,4,3,6,4,6,4,6,9};
       
        Map<Integer, Integer> numMap = new HashMap<Integer, Integer>();
       
        for(int i=0; i<numArr.length; i++){
            if(numMap.containsKey(numArr[i])){
                numMap.put(numArr[i], numMap.get(numArr[i])+1);
            } else{
                numMap.put(numArr[i], 1);
            }
        }
       
        for(Integer j : numMap.keySet()){
            if(numMap.get(j) > 1){
                System.out.println("Number "+ j +" repeated "+ numMap.get(j) +" times");
            }
        }
    }
}


Output:
Number 3 repeated 2 times
Number 4 repeated 3 times
Number 6 repeated 4 times
 


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email