Why am i getting this error?

Exception in thread “main” java.util.NoSuchElementException

Please check my Code.


import java.util.*;
public class Main {

public static void printMajority(int[] arr) {
    int n = arr.length;

    HashMap<Integer,Integer> map = new HashMap<>();

    for(int i=0;i<n;i++) {
        if(map.containsKey(arr[i])) {
            map.put(arr[i],map.get(arr[i])+1);
        } else {
            map.put(arr[i],1);
        }
    }

    for(Map.Entry<Integer,Integer> data : map.entrySet()) {
        if(data.getValue() > n/3) {
            System.out.print(data.getValue() + " ");
        }
    }

}
public static void main (String args[]) {
    Scanner in = new Scanner(System.in);
    int count = in.nextInt();
    int arr[] = new int[count];

    for (int i = 0; i < count; i++) {
        arr[i] = in.nextInt();
    }
    printMajority(arr);

}

}

Hi Shivam
You were running the program without providing any input. That is why there was a noelementException.

First provide input before running the program

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.