SlideShare a Scribd company logo
1 of 3
Download to read offline
Illegal numbers.
a. Complete the method find which accepts a collection of integers and a target, and returns the
position that the integer is found in, or a flag of -1 if the integer is not in the collection. (DO
NOT use the indexOf method on ArrayList.)
public static int find(ArrayList numbers, int target) {
b. Complete the method filter which accepts two collections of integers, one set of input integers
(numbers) and one set of integers (illegal) that should be removed from the list. Your method
should use the find method above. (DO NOT use the removeAll method on ArrayList.)
public static ArrayList filter( ArrayList numbers, ArrayList illegal) {
Solution
import java.util.ArrayList;
import java.util.Scanner;
public class IllegalNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList list = addElementsToList();
System.out.println("List : ");
print(list);
System.out.println("Enter the element to search in the list : ");
int searchElement = sc.nextInt();
int pos = find(list, searchElement);
if(pos == -1){
System.out.println("Element is not in the list");
}
else{
System.out.println("Element found in the position : "+pos);
}
System.out.println("Enter illegal integer list : ");
ArrayList illegal = addElementsToList();
System.out.println("First list : ");
print(list);
System.out.println("Illegal list : ");
print(illegal);
System.out.println("New List After performing Filter is : ");
list = filter(list, illegal);
for(Integer i : list){
System.out.print(i+" " );
}
}
public static int find(ArrayList numbers, int target) {
for(int i = 0; i < numbers.size(); i++){
if( numbers.get(i) == (Integer)target) return (i+1);
}
return -1;
}
public static ArrayList filter( ArrayList numbers, ArrayList illegal) {
ArrayList filteredArrayList = new ArrayList();
for (int i = 0; i < numbers.size(); i++){
if (!illegal.contains(numbers.get(i))){
filteredArrayList.add((Integer) numbers.get(i));
}
}
return filteredArrayList;
}
public static ArrayList addElementsToList (){
ArrayList list = new ArrayList ();
Scanner sc = new Scanner(System.in);
System.out.println("Enter the numbers in the list press 'q/Q to Stop ");
for(;;){
String newInt = sc.next();
if(newInt.equalsIgnoreCase("q")){
break;
}
else{
list.add(Integer.parseInt(newInt));
}
}
return list;
}
public static void print(ArrayList< Integer> someList) {
for(Integer i:someList)
System.out.print(i + " ");
System.out.println();
}
}

More Related Content

Similar to Illegal numbers.a. Complete the method find which accepts a collec.pdf

2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdfarshin9
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdff3apparelsonline
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfrajeshjangid1865
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
 
import java.util.LinkedList; import java.util.Random; import jav.pdf
import java.util.LinkedList; import java.util.Random; import jav.pdfimport java.util.LinkedList; import java.util.Random; import jav.pdf
import java.util.LinkedList; import java.util.Random; import jav.pdfaquastore223
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfaamousnowov
 
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docxJAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docxGavinUJtMathist
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
Create a class called IntegerArrayHelper that has the following attrib.docx
Create a class called IntegerArrayHelper that has the following attrib.docxCreate a class called IntegerArrayHelper that has the following attrib.docx
Create a class called IntegerArrayHelper that has the following attrib.docxlez31palka
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdfaryan9007
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docxdavinci54
 
Bubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptxBubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptxKalpana Mohan
 
Java Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfJava Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfirshadoptical
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfimport java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfshettysachin2005
 

Similar to Illegal numbers.a. Complete the method find which accepts a collec.pdf (20)

2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
import java.util.LinkedList; import java.util.Random; import jav.pdf
import java.util.LinkedList; import java.util.Random; import jav.pdfimport java.util.LinkedList; import java.util.Random; import jav.pdf
import java.util.LinkedList; import java.util.Random; import jav.pdf
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docxJAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Array list
Array listArray list
Array list
 
Create a class called IntegerArrayHelper that has the following attrib.docx
Create a class called IntegerArrayHelper that has the following attrib.docxCreate a class called IntegerArrayHelper that has the following attrib.docx
Create a class called IntegerArrayHelper that has the following attrib.docx
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
Searching
SearchingSearching
Searching
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
Bubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptxBubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptx
 
Java Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfJava Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdf
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdfimport java.util.ArrayList; import java.util.Scanner;public clas.pdf
import java.util.ArrayList; import java.util.Scanner;public clas.pdf
 

More from gopalk44

My protease appears to affect bacteria, but not my own cells. What t.pdf
My protease appears to affect bacteria, but not my own cells. What t.pdfMy protease appears to affect bacteria, but not my own cells. What t.pdf
My protease appears to affect bacteria, but not my own cells. What t.pdfgopalk44
 
Name the phases in interphase, and describe what happens during those.pdf
Name the phases in interphase, and describe what happens during those.pdfName the phases in interphase, and describe what happens during those.pdf
Name the phases in interphase, and describe what happens during those.pdfgopalk44
 
Look for at least four definitions of accounting (from four differen.pdf
Look for at least four definitions of accounting (from four differen.pdfLook for at least four definitions of accounting (from four differen.pdf
Look for at least four definitions of accounting (from four differen.pdfgopalk44
 
Match the word or phrase with the best description of it. ;An express.pdf
Match the word or phrase with the best description of it. ;An express.pdfMatch the word or phrase with the best description of it. ;An express.pdf
Match the word or phrase with the best description of it. ;An express.pdfgopalk44
 
JAVAThe mean of a list of numbers is its arithmetic average. The .pdf
JAVAThe mean of a list of numbers is its arithmetic average. The .pdfJAVAThe mean of a list of numbers is its arithmetic average. The .pdf
JAVAThe mean of a list of numbers is its arithmetic average. The .pdfgopalk44
 
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdfKnow and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdfgopalk44
 
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfgopalk44
 
how many chromosomes will be found in each cell at the end of anapha.pdf
how many chromosomes will be found in each cell at the end of anapha.pdfhow many chromosomes will be found in each cell at the end of anapha.pdf
how many chromosomes will be found in each cell at the end of anapha.pdfgopalk44
 
how are the technological approaches of cloning and IPSCs similar to.pdf
how are the technological approaches of cloning and IPSCs similar to.pdfhow are the technological approaches of cloning and IPSCs similar to.pdf
how are the technological approaches of cloning and IPSCs similar to.pdfgopalk44
 
HELP! Thought I can figure this one out but got it wrong. I have one.pdf
HELP! Thought I can figure this one out but got it wrong. I have one.pdfHELP! Thought I can figure this one out but got it wrong. I have one.pdf
HELP! Thought I can figure this one out but got it wrong. I have one.pdfgopalk44
 
From a recent statistical analysis for the last five years, on an av.pdf
From a recent statistical analysis for the last five years, on an av.pdfFrom a recent statistical analysis for the last five years, on an av.pdf
From a recent statistical analysis for the last five years, on an av.pdfgopalk44
 
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdfFind asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdfgopalk44
 
Explain how a wireless device can help an organization perform busin.pdf
Explain how a wireless device can help an organization perform busin.pdfExplain how a wireless device can help an organization perform busin.pdf
Explain how a wireless device can help an organization perform busin.pdfgopalk44
 
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdf
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdfExam scores were normal in BIO 200. Jasons exam score was one stan.pdf
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdfgopalk44
 
Discuss the various types of business crimes, a business liability f.pdf
Discuss the various types of business crimes, a business liability f.pdfDiscuss the various types of business crimes, a business liability f.pdf
Discuss the various types of business crimes, a business liability f.pdfgopalk44
 
Describe the different types of ribs. Which ribs are considered “fal.pdf
Describe the different types of ribs. Which ribs are considered “fal.pdfDescribe the different types of ribs. Which ribs are considered “fal.pdf
Describe the different types of ribs. Which ribs are considered “fal.pdfgopalk44
 
Circle the best answer to the following questions. From the Bohr mod.pdf
Circle the best answer to the following questions.  From the Bohr mod.pdfCircle the best answer to the following questions.  From the Bohr mod.pdf
Circle the best answer to the following questions. From the Bohr mod.pdfgopalk44
 
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdfC++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdfgopalk44
 
Below are two possible tree topologies. How many clades are different.pdf
Below are two possible tree topologies. How many clades are different.pdfBelow are two possible tree topologies. How many clades are different.pdf
Below are two possible tree topologies. How many clades are different.pdfgopalk44
 
WriteBelow are a list of descriptions that apply to either post s.pdf
WriteBelow are a list of descriptions that apply to either post s.pdfWriteBelow are a list of descriptions that apply to either post s.pdf
WriteBelow are a list of descriptions that apply to either post s.pdfgopalk44
 

More from gopalk44 (20)

My protease appears to affect bacteria, but not my own cells. What t.pdf
My protease appears to affect bacteria, but not my own cells. What t.pdfMy protease appears to affect bacteria, but not my own cells. What t.pdf
My protease appears to affect bacteria, but not my own cells. What t.pdf
 
Name the phases in interphase, and describe what happens during those.pdf
Name the phases in interphase, and describe what happens during those.pdfName the phases in interphase, and describe what happens during those.pdf
Name the phases in interphase, and describe what happens during those.pdf
 
Look for at least four definitions of accounting (from four differen.pdf
Look for at least four definitions of accounting (from four differen.pdfLook for at least four definitions of accounting (from four differen.pdf
Look for at least four definitions of accounting (from four differen.pdf
 
Match the word or phrase with the best description of it. ;An express.pdf
Match the word or phrase with the best description of it. ;An express.pdfMatch the word or phrase with the best description of it. ;An express.pdf
Match the word or phrase with the best description of it. ;An express.pdf
 
JAVAThe mean of a list of numbers is its arithmetic average. The .pdf
JAVAThe mean of a list of numbers is its arithmetic average. The .pdfJAVAThe mean of a list of numbers is its arithmetic average. The .pdf
JAVAThe mean of a list of numbers is its arithmetic average. The .pdf
 
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdfKnow and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
Know and understand the contributions of Hooke, van Leeuwenhoek, Cohn.pdf
 
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
 
how many chromosomes will be found in each cell at the end of anapha.pdf
how many chromosomes will be found in each cell at the end of anapha.pdfhow many chromosomes will be found in each cell at the end of anapha.pdf
how many chromosomes will be found in each cell at the end of anapha.pdf
 
how are the technological approaches of cloning and IPSCs similar to.pdf
how are the technological approaches of cloning and IPSCs similar to.pdfhow are the technological approaches of cloning and IPSCs similar to.pdf
how are the technological approaches of cloning and IPSCs similar to.pdf
 
HELP! Thought I can figure this one out but got it wrong. I have one.pdf
HELP! Thought I can figure this one out but got it wrong. I have one.pdfHELP! Thought I can figure this one out but got it wrong. I have one.pdf
HELP! Thought I can figure this one out but got it wrong. I have one.pdf
 
From a recent statistical analysis for the last five years, on an av.pdf
From a recent statistical analysis for the last five years, on an av.pdfFrom a recent statistical analysis for the last five years, on an av.pdf
From a recent statistical analysis for the last five years, on an av.pdf
 
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdfFind asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
Find asymptotic upperlower bounds. Find asymptotic upperlower boun.pdf
 
Explain how a wireless device can help an organization perform busin.pdf
Explain how a wireless device can help an organization perform busin.pdfExplain how a wireless device can help an organization perform busin.pdf
Explain how a wireless device can help an organization perform busin.pdf
 
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdf
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdfExam scores were normal in BIO 200. Jasons exam score was one stan.pdf
Exam scores were normal in BIO 200. Jasons exam score was one stan.pdf
 
Discuss the various types of business crimes, a business liability f.pdf
Discuss the various types of business crimes, a business liability f.pdfDiscuss the various types of business crimes, a business liability f.pdf
Discuss the various types of business crimes, a business liability f.pdf
 
Describe the different types of ribs. Which ribs are considered “fal.pdf
Describe the different types of ribs. Which ribs are considered “fal.pdfDescribe the different types of ribs. Which ribs are considered “fal.pdf
Describe the different types of ribs. Which ribs are considered “fal.pdf
 
Circle the best answer to the following questions. From the Bohr mod.pdf
Circle the best answer to the following questions.  From the Bohr mod.pdfCircle the best answer to the following questions.  From the Bohr mod.pdf
Circle the best answer to the following questions. From the Bohr mod.pdf
 
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdfC++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
C++ ProgramN-number queue rotations.[16] Write methods void Que.pdf
 
Below are two possible tree topologies. How many clades are different.pdf
Below are two possible tree topologies. How many clades are different.pdfBelow are two possible tree topologies. How many clades are different.pdf
Below are two possible tree topologies. How many clades are different.pdf
 
WriteBelow are a list of descriptions that apply to either post s.pdf
WriteBelow are a list of descriptions that apply to either post s.pdfWriteBelow are a list of descriptions that apply to either post s.pdf
WriteBelow are a list of descriptions that apply to either post s.pdf
 

Recently uploaded

Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

Illegal numbers.a. Complete the method find which accepts a collec.pdf

  • 1. Illegal numbers. a. Complete the method find which accepts a collection of integers and a target, and returns the position that the integer is found in, or a flag of -1 if the integer is not in the collection. (DO NOT use the indexOf method on ArrayList.) public static int find(ArrayList numbers, int target) { b. Complete the method filter which accepts two collections of integers, one set of input integers (numbers) and one set of integers (illegal) that should be removed from the list. Your method should use the find method above. (DO NOT use the removeAll method on ArrayList.) public static ArrayList filter( ArrayList numbers, ArrayList illegal) { Solution import java.util.ArrayList; import java.util.Scanner; public class IllegalNumber { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList list = addElementsToList(); System.out.println("List : "); print(list); System.out.println("Enter the element to search in the list : "); int searchElement = sc.nextInt(); int pos = find(list, searchElement); if(pos == -1){ System.out.println("Element is not in the list"); } else{ System.out.println("Element found in the position : "+pos); } System.out.println("Enter illegal integer list : "); ArrayList illegal = addElementsToList(); System.out.println("First list : ");
  • 2. print(list); System.out.println("Illegal list : "); print(illegal); System.out.println("New List After performing Filter is : "); list = filter(list, illegal); for(Integer i : list){ System.out.print(i+" " ); } } public static int find(ArrayList numbers, int target) { for(int i = 0; i < numbers.size(); i++){ if( numbers.get(i) == (Integer)target) return (i+1); } return -1; } public static ArrayList filter( ArrayList numbers, ArrayList illegal) { ArrayList filteredArrayList = new ArrayList(); for (int i = 0; i < numbers.size(); i++){ if (!illegal.contains(numbers.get(i))){ filteredArrayList.add((Integer) numbers.get(i)); } } return filteredArrayList; } public static ArrayList addElementsToList (){ ArrayList list = new ArrayList (); Scanner sc = new Scanner(System.in); System.out.println("Enter the numbers in the list press 'q/Q to Stop "); for(;;){
  • 3. String newInt = sc.next(); if(newInt.equalsIgnoreCase("q")){ break; } else{ list.add(Integer.parseInt(newInt)); } } return list; } public static void print(ArrayList< Integer> someList) { for(Integer i:someList) System.out.print(i + " "); System.out.println(); } }