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. Assume that the list will always contain less than 20 integers.

That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a space, even the last one.

Ex: If the input is:

5 25 51 0 200 33
0 50
then the output is:

25 0 33
(the bounds are 0-50, so 51 and 200 are out of range and thus not output).

To achieve the above, first read the list of integers into an array.

Respuesta :

Answer:

import java.util.Scanner;

public class ListOfIntegers {

public static void main(String[] args) {

 // Create an object of the Scanner class to allow for user input

 Scanner input = new Scanner(System.in);

 // Prompt the user for the number of integers they want to enter

 System.out.print("Enter the number of integers : ");

 // Get and store the number of integers entered by user

 int n = input.nextInt();

 System.out.println();

 // Create an array to hold the integers

 // The array has the same length as the number of integers

 int[] numbers = new int[n];

 // Create a loop that asks the user to enter all integers

 // At each cycle of the loop, save the entered integer into the array

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

  System.out.print("Enter number " + (i + 1) + " : ");

  numbers[i] = input.nextInt();

  System.out.println();

 }

 // Prompt the user for the lower bound

 System.out.print("Enter the lower bound : ");

 // Get and store the lower bound in a variable

 int lowerbound = input.nextInt();

 System.out.println();

 // Prompt the user for the upper bound

 System.out.print("Enter the upper bound : ");

 // Get and store the upper bound in a variable

 int upperbound = input.nextInt();

 System.out.println();

 System.out.println("OUTPUT :: ");

 // Create a loop to cycle through the array of numbers.

 // At each cycle, check if the array element is within range.

 // If it is within range, print it to the console

 for (int j = 0; j < numbers.length; j++) {

  if (numbers[j] >= lowerbound && numbers[j] <= upperbound) {

   System.out.print(numbers[j] + " ");

  }

 }

}

}

Explanation:

Please go through the comments in the code for more readability and understanding. The source code file has been attached to this response. Kindly download the file to get a better formatting of the code.

Hope this helps!

Ver imagen stigawithfun

Answer:

integers=[]

while True:

      number=int(input())

      if number<0:

       break

      integers.append(number)  

print("",min(integers))

print("",max(integers))

Explanation:

ACCESS MORE
EDU ACCESS
Universidad de Mexico