Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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) + " "); } } student submitted image, transcription available below

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 mode

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

6. Describe why communication is vital to everyone

Answered: 1 week ago