Respuesta :
Answer:
import java.util.Arrays;
import java.util.Scanner;
import java.util.Collections;
public class num1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("How many numbers: ");
int num = in.nextInt();
int [] numArray = new int[num];
for(int i =0; i<numArray.length; i++){
System.out.println("Enter the numbers: ");
numArray[i]= in.nextInt();
}
//Print the list of numbers entered
System.out.println("You entered these numbers "+ Arrays.toString(numArray));
//finding the minimum
int min = numArray[0];
for(int i =0; i<numArray.length; i++){
if (numArray[i]<min) {
min = numArray[i] ;
}
}
System.out.println("The minimum is "+min);
int max = numArray[0];
for(int i =0; i<numArray.length; i++){
if (numArray[i]>max) {
max = numArray[i];
}
}
System.out.println("The maximum is "+max);
}
}
Explanation:
In the program above;
The user will be prompted to enter the length of the list (n) with the assumption that it will always be more than two
An array is created of the size (n)
User is prompted to enter the numbers in the list
Using a combination of for loops and if statements, the max and min is outputed