// Most Frequent Number? // import java.util.Random; public class Program3 { public static void main(String[] args) { Random rand = new Random(); // initialize the count array int[] count = new int[51]; for(int i=0; i< 51; i++) count[i]=0; // generate the random numbers for(int i=0; i< 100; i++) { int num = rand.nextInt(51)-25; count[num+25]++; } // print the count for all numbers for(int i=-25; i<= 25; i++) System.out.println( i + "\t" + count[i+25]); // find the most frequent number int max = count[0]; int maxId = 0; for(int i=-25; i<= 25; i++) { if(count[i+25] > max) { max= count[i+25]; maxId = i; } } System.out.println("Most Frequent Number is " + maxId + " count " + max); } }