In: Computer Science
Design a modular program that accepts as input 20 numbers between 0 and 100 (including 0 and 100). The program should store the numbers in an array and then display the following information:
The lowest number in the array
The highest number in the array
The total of the numbers in the array
The average of the numbers in the array
Your program should consist of the following:
Module main. Accepts input of numbers and assigns them to an array. The array is traversed in order to find the highest number, lowest number, total and average of the numbers.
Module showStats. Displays the highest number, lowest number, total and average of the numbers.
Expected Input/Output
Please enter 20 numbers between 1-100:
64
93
12
45
85
.
.
.
27
43
2
The lowest number in the array is: 1
The highest number in the array is: 95
The total of the numbers in the array is: 811
The average of the numbers in the array is: 40.55
The solution should be in Java. Thank you
Program Code Screenshot :
Sample Output :
Program Code to Copy
import java.util.Scanner; class Main{ static int[] readInt(){ //Read user input Scanner obj = new Scanner(System.in); int A[] = new int[20]; //Read 20 integers System.out.println("Please enter 20 numbers between 1-100:"); for(int i=0;i<20;i++){ A[i] = obj.nextInt(); } return A; } static void showStats(int A[]){ //Initialize highest, lowest and total int highest = A[0]; int lowest = A[0]; int total = 0; for(int x : A){ //Update highest, lowest and total highest = Math.max(highest,x); lowest = Math.min(lowest,x); total += x; } //Find average double avg = (total*1d)/A.length; System.out.println("The lowest number in the array is: "+lowest); System.out.println("The highest number in the array is: "+highest); System.out.println("The total of the numbers in the array is: "+total); System.out.println("The average of the numbers in the array is: "+avg); } public static void main(String[] args) { int A[] = readInt(); showStats(A); } }