Question: JAVA Do the following steps: Create a class FillRandom. Do your work in the fillRandom() method. Prompt the user with Enter a positive integer:. Set
JAVA
Do the following steps:
Create a class FillRandom.
Do your work in the fillRandom() method.
Prompt the user with "Enter a positive integer:".
Set up a Scanner to read from the keyboard and take in a positive integer randomSize from the user.
Allocate a double array whose length is 1,000,000.
Loop over the elements of the array, assigning array[k] the next double random number between 0 and randomSize. You will have to scale up the java.util.Random.nextRandom() value, which is in the range [0...1). You want it to be in the range [0...randomSize). So you must multiply it by randomSize, as shown in code above.
Now loop over the array again, computing the min, max and average of its values. You may want to use the Math.min() and Math.max() methods from java.lang.Math. (SAVE YOUR CODE before clicking on this link)
Print out the min value with "Min = " and the minimum
Print out the max value with "Max = " and the maximum
Print out the average with "Average = " and the average
Notice that the minimum over many random numbers in [0...n) is close to zero, the max is close to n, and the average is close to n/2.
In order to pass tests, use the following format:
Enter a positive integer: Min = <> Max = < > Average = < >
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
