hi! i have written a program that takes a random number from 0-999, 10000 times. I have the program calculating how many times each number comes up randomly, and finds the mode. But my program doesn't include how to find multiple largest numbers, ex. 2 and 4 each come up 18 times, but it only prints 2, because it comes first. Can anyone help me on how I can print multiple largest numbers? Thanks!
import java.util.Random;
public class modeofnumbers {
public static void main(String[] args) {
Random randGen = new Random(1);
int[] nums = new int[10000];
for (int i=0; i<nums.length; i++) {
nums[i] = randGen.nextInt(1000);
}
int[] count = new int[1000];
for (int i=0; i<nums.length; i++){
int digit = Integer.valueOf(nums[i]);
count[digit]++;
}
System.out.println("Digit: Frequency:");
for (int i=0; i<1000; i++) {
System.out.println(i + "\t" + count[i]);
}
int highIndex = 0;
for (int i=0; i<10; i++) {
if (count[i] > count[highIndex]) {
highIndex = i;
}
}
System.out.println("Mode = " + highIndex);
}
}