Ask Question
25 May, 06:58

Ex: If the input is: 2 3 4 8 11 the output is: 4 The maximum number of inputs for any test case should not exceed 9. If exceeded, output "Too many inputs". Hint: First read the data into a list. Then, based on the list's size, find the middle item.

+2
Answers (1)
  1. 25 May, 10:19
    0
    The solution is given in the explanation section

    pay attention to the explanation given as comments

    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 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));

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Ex: If the input is: 2 3 4 8 11 the output is: 4 The maximum number of inputs for any test case should not exceed 9. If exceeded, output ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers