86.9k views
2 votes
The following segment of code is meant to remove the even numbers from an ArrayList list and print the results:

int counter = 0;
while(counter < list.size())
{
if(list.get(counter) %2 == 0)
{
list.remove(counter);
}
counter++;
}
System.out.println(list.toString());
The method as written, however, is incorrect. Which ArrayList(s) list would prove that this method was written incorrectly?

I.
[1, 2, 3, 4, 5]
II.
[2, 4, 5, 6, 7]
III.
[2, 4, 6, 8, 10]
IV.
[2, 5, 6, 7, 8]
III only


II and IV


II only


I and IV


II and III

2 Answers

3 votes

Answer:

II and III

Step-by-step explanation:

The following segment of code is meant to remove the even numbers from an ArrayList-example-1
User Lmsimp
by
4.8k points
6 votes

Answer:

II and III

Step-by-step explanation:

I took the quiz and got this wrong, but it gives you the answer afterwards, just trying to help everyone else out.

User Robert Swisher
by
4.5k points