Java – Count Frequency in a Randomly Generated List of Numbers


I generated 100 random numbers from 0-9, I am supposed to count how many times each number appears. Storing it in an array of 10 integers and count it.

Here's what I have so far, I cant figure out the count part.

Random r = new Random();
int[] integers = new int[100];

for (int i=0; i<integers.length; i++)
  integers[i] = (r.nextInt(10)+0);

Best Solution

Here's a clue: You need to take the approach whereby the array index represents the number being stored, and the value of that array element equals the frequency.

Good luck!

Related Question