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) + " "); } }
Activity 1 Write a program called AnalyzeNumbers. This program will have array that holds 10 random integers from 1 to 5. Output the 10 random numbers to the screen using an enhanced for loop. This program will also have a method called frequency that takes an integer array as the parameter and It will return an array that holds the frequency of numbers. Index 0 will hold the frequency of 1, Index 1 will hold the frequency of 2, and so on. Use this method in your program to create an array that holds the frequency of the random numbers in your array. Use an enhanced for loop to output the frequency of each number. Then display the number that appears the most in your array-you will need to account for numbers appearing the same amount for the modeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started