import java.util.Scanner;
import java.util.Arrays;
//Display the number of occurrences of each an element in an array
public class Arrays_Exercise3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the no. of elements you wish to enter: ");
int n = input.nextInt();
int[] num = new int[n];
System.out.print("Enter " + n + " integers: ");
for (int i = 0; i < n; i++){
num[i] = input.nextInt();
}
for (int i : num) {
System.out.print(i + " ");
}
System.out.println();
int l=0, count;
while(l<=n){
count = 0;
for(int i=0; i<n; i++){
if(num[i]==l)
{
count++;
}
}
if (count != 0) {
System.out.println(l+" occurs "+count+" times");
}
l++;
}
}
}
Tried on with this code but if the user enters the number which is greater than the number for limit of numbers, the occurrence does not show up. Would be really great if anyone could help.