Answered You can hire a professional tutor to get the answer.
I have tried this question so many different ways and I keep getting an error that says "Do not call Math.random() in this course. Instead use...
I have tried this question so many different ways and I keep getting an error that says "Do not call Math.random() in this course. Instead use StdRandom" ... I need to use Math.random for the assignment though. Here is the question followed by my code. Please point out what I am doing wrong.
A program, "RanNumGen," that takes an integer command-line argument "n" that indicates the number of random numbers to generate and uses the method "Math.random()" to print uniform random values between 1 and 100 (both inclusive), and then prints the minimum and maximum value.
- Sample runs would be as follows.
- >java RanNumGen 5
- 67 24 31 11 80
- The minimum value is 11.
- The maximum value is 80.
- >java RanNumGen 8
- 2 76 29 96 91 98 35 16
- The minimum value is 2.
- The maximum value is 98.
My Code:
public class RanNumGen
{
public static void main(String[] args)
{
int n = Integer.parseInt(args[0]);
int counter = 0;
int max = 100;
int min = 0;
int r = 0;
int val = 0;
//
while (counter < n)
{
r = (int) (Math.random() * (101 - 0) + 0);
val = r;
if (val < min) {
min = val;
}
if (val > max) {
max = val;
}
//
System.out.print((r+" "));
counter = counter + 1;
}
System.out.printf("%n");
System.out.println("The minimum value is: " + min);
System.out.println("The maximum value is: " + max);
}
}