In: Computer Science
in JAVA
Create a class called “MinMax” that satisfies the following
requirements:
a. create an integer array called nums that has 20 cells
b. generate a random number between 5 and 30, and populate the
array nums
c. print the minimum and maximum number in the array nums
d. print sum and average of numbers in the array nums
Your output look like this: (Note: numbers shown below will be
different in your program due to the random numbers)
minimum number = 6
maximum number = 29
sum = 123
average = 67.23
ANSWER: HEre i am giving you the code and output please like it.
CODE:
import java.util.concurrent.ThreadLocalRandom;
public class MinMax {
public static void main(String[] args) {
// TODO Auto-generated method
stub
int arr [] = new int[20];
for (int i = 0; i < 20; i++) {
arr[i] =
ThreadLocalRandom.current().nextInt(5, 30);
}
int max=arr[0];
int min=arr[0];
int sum=0;
for(int i=0;i<20;i++) {
if(arr[i]>max)
max=arr[i];
if(arr[i]<min)
min=arr[i];
sum+=arr[i];
}
System.out.println("minimum number = "+min);
System.out.println("maximum number = "+max);
System.out.println("sum = "+sum);
double avg=(double)sum/20;
System.out.printf("average = %.2f",avg);
}
}
OUTPUT: