Question
import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; import java.util.Scanner; public class LinkedListTester10 { public static void main(String[] args) { LinkedList < String > list = new
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;
public class LinkedListTester10 {
public static void main(String[] args) {
LinkedList < String > list = new LinkedList < String > ();
for (int i = 1; i <= 50; i++) {
list.add(i + "");
}
System.out.println(list); //-----------Start below here. To do: approximate lines of code = 4 // 1-4. Use an iterator to remove all elements containing "3"
Iterator it = list.iterator();
while(it.hasNext()) {
String str = it.next();
if(str.contains("3")) {
it.remove();
}
}
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
System.out.println(list) ;
//System.out.println("Expected:[1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50]");
}
}
My code is not working, please fix it and include screenshots. Thank you
Step by Step Solution
3.43 Rating (153 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started