Answer:
public class Main
{
public static void main(String[] args) {
int[] arr = {3, 1, 1, 2, 4, 4, 4, 6};
int[] o = countOccurance(arr);
for (int x: o)
System.out.print(x + " ");
}
public static int[] countOccurance(int[] arr){
int[] occ = new int[6];
for (int x: arr)
occ[x-1]++;
return occ;
}
}
Explanation:
Create a function called countOccurance that takes one parameter, an array
Inside the function, initialize an array, occ, to hold the occurance counts
Create a for each loop to iterate the array, and increment the occurance of the numbers
When the loop is done, return the occ array
Inside the main, initialize an array
Call the function countOccurance and set it to a new array, o
Print the elements of the o to see the number of occurances of the numbers