Answer:
The solution is given in the explanation section
pay attention to the explanation given as comments
Step-by-step explanation:
//Import all needed classes
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class num9 {
public static void main(String[] args) {
//Use scanner to receive user inputs
Scanner in = new Scanner(System.in);
//Create a list to store values entered by user
List<Integer> list = new ArrayList<>();
int n;
//Use to loop to continously prompt and receive inputs
//Break out of loop when a negative value is entered
do {
System.out.println("Enter Scores, Enter a negative number to breakout");
n = in.nextInt();
list.add(n);
} while (n >= 0);
//Remove the last value (negative value to breakout of loop) entered to end the loop
list.remove(list.size() - 1);
//Check if user entered more than 9 values
if (list.size() > 9) {
System.out.println("Too many inputs");
} else {
//Print the entire list
for(int i:list){
System.out.print(i+" ");
}
//Find the middle item
int indexMiddle = list.size()/2;
System.out.println();
System.out.println(list.get(indexMiddle));
}
}
}