Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 50 60 140 200 75 100

Respuesta :

Answer:

Explanation:

The following is coded in Java. It asks the user for the number of inputs and then creates a loop to read all of the inputs and adds them to an ArrayList. Then it saves the last value in the array as the threshold. Finally, it loops through the array printing only the values less than or equal to the threshold. The program has been tested and the output can be seen in the image below.

import java.util.ArrayList;

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       ArrayList<Integer> myList = new ArrayList<>();

       System.out.println("How many inputs will you add? ");

       int inputs = in.nextInt();

       System.out.println("Enter inputs: ");

       for (int i = 0; i< inputs; i++) {

           int num = in.nextInt();

           myList.add(num);

       }

       int threshold = myList.get(myList.size()-1);

       System.out.println("Inputs Less than or Equal to Threshold: ");

       for (int x: myList) {

           if (x <= threshold) {

               System.out.println(x);

           }

       }

   }

}

Ver imagen sandlee09