Question: I finished the code but did not add the method for frequency. Could you please add the method for frequency and make sure the code
I finished the code but did not add the method for frequency. Could you please add the method for frequency and make sure the code follows the instructions carefully. Thank you! My code is below. Please highlight the changes.
import java.util.Random; public class AnalyzeNumbers { public static void main(String args[]) { Random rnumbers = new Random(); // declaring variables int[] numbers = new int[10]; for(int i=0; i<10; i++) numbers[i] = rnumbers.nextInt(5) + 1; System.out.print("Array is "); for(int num: numbers) {System.out.print(num + " ");} System.out.println(); int[] freq = new int[5]; for(int i=0; i<10; i++) freq[numbers[i]-1]++; int y=1; for(int num: freq) {System.out.println("Frequency of the number "+ y+ " is "+num); y++; } int mostfrequent = freq[0]; int index = 0; for(int i=1; i<5; i++) if(freq[i] > mostfrequent) { mostfrequent = freq[i]; index = i; } System.out.print("The most frequent value in the array: "); for(int i=1; i<5; i++) if(freq[i] == mostfrequent) System.out.print((i+1) + " "); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
