java Elements in a range 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 fewer 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 comma, even the last one. The output ends with a newline. 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.

Answers

Answer 1

Answer:

The program in Java is:

import java.util.Scanner;

public class MyClass {

   public static void main(String args[]) {

     Scanner input = new Scanner(System.in);

     int n;

     n = input.nextInt();

     int [] mylist = new int[n+1];

     mylist[0] = n;

     System.out.print("List elements: ");

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

         mylist[i] = input.nextInt();

     }

     int min,max;

     System.out.print("Min & Max: ");

     min = input.nextInt();

     max = input.nextInt();

     

     for(int i=1; i < mylist.length; i++){

         if(mylist[i]>=min && mylist[i]<=max){

             System.out.print(mylist[i]+" ");

 }

}

   }

}

Explanation:

This line declares length of list

     int n;

This line gets length of list

     n = input.nextInt();

This line declares the list/array

     int [] mylist = new int[n+1];

This line initializes the element at index 0 to the length of the list

     mylist[0] = n;

This prompts user for elements of the list/array

     System.out.print("List elements: ");

The following iteration gets list elements

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

         mylist[i] = input.nextInt();

     }

This declares the lower and upper bound (min, max)

     int min,max;

This line prompts user for elements of the list/array

     System.out.print("Min & Max: ");

This next two lines get the bound of the list/array

     min = input.nextInt();

     max = input.nextInt();

The following iteration prints the elements in the range

     for(int i=1; i < mylist.length; i++){

         if(mylist[i]>=min && mylist[i]<=max){

             System.out.print(mylist[i]+" ");

 }

}


Related Questions

please help me



Match the technology with the appropriate task.



1. graphics software

2. word processor

3. CAD

4. laptop

5. GPS​

Answers

Complete Question:

Match the technology with the appropriate task.

Column A

1. Graphics software

2. Word processor

3. CAD

4. Laptop

5. GPS

Column B

A. Create a company logo.

B. Get directions to a customer’s office.

C. Type a report.

D. Complete many types of tasks on a computer away from the office.

E. Design a building.

Answer:

1. A

2. C

3. E

4. D

5. B

Explanation:

1. Graphics software: it can be used to create a company logo. Some examples of software applications or programs are Adobe photoshop, Core-draw, illustrator etc.

2. Word processor: it is typically used for typing a text-based document. For instance, type a report. Some examples are notepad, Microsoft Word, etc.

3. CAD: design a building. CAD is an acronym for computer aided design used for designing the graphical representation of a building plan. An example is Auto-CAD.

4. Laptop: complete many types of tasks on a computer away from the office. A laptop is compact and movable, so it can be easily used in any location.

5. GPS: directions to a customer’s office. GPS is an acronym for global positioning system and it is typically used for locating points and directions of a place.

Answer:

1. A

2. C

3. E

4. D

5. B

If an insurance policy covers individual losses up to $10,000 and has a deductible of
$500, the insured will be paid how much in the event of a covered loss of $5,000?

Answers

Answer: $4500

Explanation:

The deductible is the amount that the insured that is, the policy holder will have to pay. In this case, there is a covered loss of $5000 and the insured has a deductible of $500.

Therefore, the amount that the insured will be paid will be the difference between $5000 and the deductible of $500. This will be:

= $5000 - $500

= $4500

rheumatoid arthritis is caused when​

Answers

Answer:

caused by the immune system attacking healthy body tissue.

Explanation:

all though they are not sure what triggers it

Universal Container wants to understand all of the configuration changes that have been made over the last 6 months. Which tool should an Administrator use to get this information

Answers

Answer:

Set up audit trail

Explanation:

The administrator should set up an audit trail in order to get this information.

An audit trail would give him the record of all the configuration changes that have been made in a file or a database in the last 6 months.

Audit trails can be manual or electronic. It provides history and also documentation support. It can authenticate security and also help to mitigate challenges.

Other Questions
Which is most similar to the word indignation?CalmDelightAngerO Pleasurehing Which best explains the role of plants in the nitrogen cycle? Leah is purchasing a condominium and is financing $515,000 with a 20-year 5/1 ARM at 5.25% with a 1/12 cap structure. What will her payments be at the beginning of year 6? (3 points) a $3155.38 b $3701.45 c $3470.30 d $2908.95 "When is war justified?" hi every one be safe and have a great rest of your week plz pass this on and add 100 points to it to make some ones day :) :) :) :) Which division of Christianity adopted the art and architecture of the Byzantine Empire?Group of answer choicesPresbyterianEastern OrthodoxCatholicBaptist What is the interest on Rr 20,000 if the interest rate is 15%? Which three lengths could be of the sides of a triangle? Which of these is an example of physical systems impacting the environment? (4points). 1. A flood causes erosion and loss of shoreline. 2. People fill a lake before building houses near it. 3. An earthquake causes a building to fall. 4. A native tribe considers a volcano to be sacred. What is the definition of "earth overshoot day?" 4. A rectangle has a diagonal of 8 cm. The diagonal creates a 60 angle at the base of the rectangle.[2]a. Draw a picture of the rectangle[4]b. Write an EXACT expression for the base and the height of the rectangle.[2]C. Use your expressions to find the EXACT area of the rectangle. What is perspective? ANSWER NOW AND YOU GET 20 and ill answer one of ur questions Karen had to spend $24 on seven packs of markers for a workshop. After buying them, she had $10. How much did each pack of markers cost? Will give brainliest If each of the numbers in the following data set were multiplied by 17, whatwould be the median of the data set?28, 58, 20, 14, 18, 71, 36A. 986B. 1207C. 476D. 612 What group of people did Louis draw from his advisor? Watch the TEDtalk How to make stress your friend What do you think could be useful for you in your stress management? -5x2y - 3x4Whats the answer You have to multiply properties of exponents and simplify it Chapter 1: Beliefs and TeachThe following statements are muddled up. Add them in the correct order to the flowchartbelow, to retell the story of Creation as described in Genesis chapters 2 and 3.Adam and Eve lived in a garden full of wonderful trees and plantsThey disobeyed God's command and ate from the treeGod told Adam and Eve not to eat from the tree of the knowledgeof good and evilAdam and Eve became afraid and hid from GodGod created the universe including the first humans, Adam and EveAdam and Eve had to leave the gardenAdam and Eve were tempted by the snake to eat from the forbidden tree.