Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of integers. For example, if nums contains {

Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of integers. For example, if nums contains {1,2,2,3,4,3,5,5,6}, then after executing remDups(nums), nums should contain {1,2,3,4,3,5,6}.
public static void remDups(ArrayList nums)
{
for (int j =0; j < nums.size()-1; j++)
{
if (nums.get(j).equals(nums.get(j +1)))
{
nums.remove(j);
j++;
}
}
}
The code does not always work as intended. Which of the following lists can be passed to remDups to show that the method does NOT work as intended?
A.{1,1,2,3,3,4,5}
B.{1,2,2,3,3,4,5}
C.{1,2,2,3,4,4,5}
D.{1,2,2,3,4,5,5}
E.{1,2,3,3,4,5,5}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions