Question

Write a program that first gets a list of integers from the input and adds them...

Write a program that first gets a list of integers from the input and adds them to an array. The input begins with an integer indicating the number of integers that follow (Your program should work for any size of the array). Then, get the last value from the input, and output all integers less than or equal to that value by iterating through the array.

Ex: If the input is:

Enter the number of integers: 5

Enter integer 1: 50

Enter integer 2: 60

Enter integer 3: 140

Enter integer 4: 200

Enter integer 5: 75

Display integer less than or equal to: 100

the output is: The integers less than or equal to 100 are:

50

60

75

The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75. The 100 indicates that the program should output all integers less than or equal to 100, so the program outputs 50, 60, and 75. Such functionality is common on sites like Amazon, where a user can filter results.

Please help me with this program in Java with comments.

Thank you

1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1
import java.util.Scanner;

public class LabProgram {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        System.out.print("Enter the number of integers: ");
        int numValues = scnr.nextInt();
        int[] userValues = new int[numValues];
        for (int i = 0; i < numValues; i++) {
            System.out.print("Enter integer " + (i + 1) + ": ");
            userValues[i] = scnr.nextInt();
        }
        System.out.print("Display integer less than or equal to: ");
        int threshold = scnr.nextInt();
        System.out.println("The integers less than or equal to " + threshold + " are:");
        for (int i = 0; i < numValues; ++i) {
            if (userValues[i] <= threshold) {
                System.out.println(userValues[i]);
            }
        }
    }
}

Enter the number of integers: 5 Enter integer 1: 50 Enter integer 2: 60 Enter integer 3: 140 Enter integer 4: 200 Enter integ

Add a comment
Know the answer?
Add Answer to:
Write a program that first gets a list of integers from the input and adds them...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • IN JAVA Write a program that first gets a list of integers from input. The input...

    IN JAVA 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 the output is: 50 60 75...

  • Write a program that first gets a list of integers from input. The input begins with...

    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, and output all integers less than or equal to that value. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75 The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75....

  • *Coral Language* Write a program that first gets a list of six integers from input. The first five values are the intege...

    *Coral Language* Write a program that first gets a list of six integers from input. The first five values are the integer list. The last value is the upper threshold. Then output all integers less than or equal to the threshold value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Such functionality is common on sites like...

  • Coral Language Please to thanks Write a program that first gets a list of 5 integers...

    Coral Language Please to thanks Write a program that first gets a list of 5 integers from input. Then, get another value from the input, and output all integers less than or equal to that value. Ex: If the input is 50 60 140 200 75 100, the output is: 50 60 75 For coding simplicity, follow every output value by a space, including the last one. Then, output a newline. Such functionality is common on sites like Amazon, where...

  • Please draw a flow chart for each method please and thank you. Write a program that...

    Please draw a flow chart for each method please and thank you. 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, and output all integers less than or equal to that value. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 50 60 140 200 75 100 the...

  • in python and can you tell me why i am wrong? Thank you ZyBooks Python M...

    in python and can you tell me why i am wrong? Thank you ZyBooks Python M X zy cS 171: Computer x zy 11.9. LAB: Output x C Write A Program 1 x Slack | Hiu Nguy TG Python Program t x p ython - Getting x +. - 5 x € → e l earn.zybooks.com/zybook/DREXELCS171 Winter2020/chapter/11/section/9 Help/FAQ Kuanyu Lai - = zyBooks Bake My library > CS 171: Computer Programming home> > 11.9: LAB: Output values in a list...

  • Write a program whose input is two integers, and whose output is the first integer

    5.20 (Ch 5) HW: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer Ex: If the input is: -15 30 Then the output is: 15 -5 5 15 25 Ex: If the second integer is less than the first as in 20 5, the output is: Second integer can't be less than the...

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • 5.21 LAB: Adjust values in a list by normalizing

    When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers.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, adjust each integer in the list by subtracting the smallest value from all the integers.Ex: If the...

  • 3.16 LAB: Output range with increment of 10 Write a program whose input is two integers,...

    3.16 LAB: Output range with increment of 10 Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT