1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alja [10]
3 years ago
14

g Create a package named lab7 (no spaces, ALL in lowercase) where you will place your lab files. Write a class FilterWith with a

method called filterRange that accepts an ArrayList of integers and two integer values min and max as parameters and removes all elements whose values are in the range min through max (inclusive). For example, if a variable called list stores the values [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7], the call of filterRange(list, 5, 7); should remove all values between 5 and 7, changing the list to store [4, 9, 2, 3, 1, 8]. If no elements in range min-max are found in the list, or if the list is initially empty, the list's contents are unchanged. Create an application that creates an object of FilterWith and invokes the filterRange method and show the results
Computers and Technology
1 answer:
sweet [91]3 years ago
3 0

Answer:

See explaination

Explanation:

import java.util.ArrayList;

import java.util.Scanner;

public class ListFilter

{

public static void filterRange(ArrayList<Integer> list,int min, int max)

{

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

for(int i=0;i<list.size();i++)

{

if(list.get(i)>=min && list.get(i)<=max) //Checking if element is between min and max

{

listNew.add(list.get(i));

}

}

list.removeAll(listNew); //removing all elements from list.

}

public static void main(String[] args)

{

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

list.add(4);

list.add(7);

list.add(9);

list.add(2);

list.add(7);

list.add(7);

list.add(5);

list.add(3);

list.add(5);

list.add(1);

list.add(7);

list.add(8);

list.add(6);

list.add(7);

Scanner sc=new Scanner(System.in);

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

int min=sc.nextInt();

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

int max= sc.nextInt();

filterRange(list, min, max);

//Displaying new List

for(int i=0;i<list.size();i++)

{

System.out.print(list.get(i)+" ");

}

}

}

You might be interested in
What are storage devices ​
devlian [24]

Answer:

<em>=</em><em>></em><em>. </em><em>storage</em><em> </em><em>devices</em><em> </em><em>are</em><em> </em><em>those</em><em> </em><em>devices</em><em> </em><em>that </em><em>is </em><em> </em><em>used </em><em>to </em><em>store</em><em> </em><em>some </em><em>data </em><em>in </em><em>it </em>

<em>It </em><em>is </em><em>very </em><em>important</em><em> </em><em>device</em><em> </em><em>that </em><em>gives </em><em>a </em><em>lot </em><em>of </em><em>benefits</em><em> </em><em>in </em><em>our </em><em>daily</em><em> lives</em>

<em>we </em><em>can </em><em>also </em><em>carry</em><em> </em><em>our </em><em>data </em><em>from </em><em>one </em><em>place</em><em> to</em><em> </em><em>another</em>

6 0
3 years ago
Read 2 more answers
How many people watch Anime in the world?
iren [92.7K]
3 to 4 billion people.

7 0
3 years ago
Read 2 more answers
Does the security burden fall primarily on the user? On
liubo4ka [24]

Answer:

yes and no because of the security

Explanation:

yes and no because of the security

6 0
3 years ago
You use a cisco 2900 router in your network. you are considering purchasing and implementing the Unifield communications feature
Olenka [21]

Explanation:

License boot module c2900, technology-package uck9

7 0
3 years ago
What is the purpose of copyfitting?
stiv31 [10]

Answer:

ms word can help you to writer and print

ur document and make u more attractive

Explanation:

a

3 0
3 years ago
Other questions:
  • What do you call the number that is used as an index to pinpoint a specific element within an array?
    14·1 answer
  • What were the goals of the “paperless society” ideal?
    14·2 answers
  • What's one way to engage teens in technology?
    8·1 answer
  • "This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some out
    15·1 answer
  • Jim is expecting a very busy weekend at his store, so he sent the following e-mail to his employees: ALL EMPLOYEES MUST WORK THI
    6·1 answer
  • Some people recommend deleting social media accounts because of the troubling legal and ethical implications of social media. Do
    9·1 answer
  • Which type of document should Omar print?
    5·2 answers
  • A small startup company has hired you to harden their new network. Because funds are limited, you have decided to implement a un
    8·1 answer
  • When would the Jerusalem virus attack?<br> 1. Friday the 13th<br> 2. Wednesday the 13th
    13·2 answers
  • What are the nuclear codes?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!