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
nevsk [136]
3 years ago
7

Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of in

tegers. 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}
Computers and Technology
1 answer:
MAXImum [283]3 years ago
3 0

Answer:

B. {1, 2, 2, 3, 3, 4, 5}

Explanation:

Given

The above code segment

Required

Determine which list does not work

The list that didn't work is B.\ \{1, 2, 2, 3, 3, 4, 5\}

Considering options (A) to (E), we notice that only list B has consecutive duplicate numbers i.e. 2,2 and 3,3

All other list do not have consecutive duplicate numbers

Option B can be represented as:

nums[0] = 1

nums[1] = 2

nums[2] = 2

nums[3] = 3

nums[4] = 3

nums[5] = 4

nums[6] = 5

if (nums.get(j).equals(nums.get(j + 1)))

The above if condition checks for duplicate numbers.

In (B), when the elements at index 1 and 2 (i.e. 2 and 2) are compared, one of the 2's is removed and the Arraylist becomes:

nums[0] = 1

nums[1] = 2

nums[2] = 3

nums[3] = 3

nums[4] = 4

nums[5] = 5

The next comparison is: index 3 and 4. Meaning that comparison of index 2 and 3 has been skipped.

<em>This is so because of the way the if statement is constructed.</em>

You might be interested in
A service specialist from your company calls you from a customer's site. He is attempting to install an upgrade to the software,
IgorLugansk [536]

Answer:

kill 1000

Explanation:

3 0
3 years ago
A teacher wants to check the typing proficiency of five students. She gives all of them the same passage to type. Which student
Hitman42 [59]

The student who uses macros for long words. They are most likely to pass words very easily because they have a macro. While not only saving time, also making a stunning performance as macros usually auto correct as well.

5 0
2 years ago
Which field uses computer programs to automate tasks so that they can be performed better than by humans ?
rewona [7]

Answer:

ran out of comments

Explanation:  :)

5 0
2 years ago
When a cells number format is “time” it will show a value in what format
Leokris [45]

The format of time shows a value of time day (what time it is).

When you choose the option of time you can have it displayed in a variety of formats, including military time and a time display that will change with regional time zones,

3 0
3 years ago
WILL UPVOTE ALL plz
OverLord2011 [107]
D-ash is the answer.
8 0
3 years ago
Other questions:
  • Which of the following would an A/V technician NOT typically do? (Select all that apply).
    14·1 answer
  • When you add an rss feed to hootsuite publisher, posts from blogs and websites you designate will be?
    5·1 answer
  • How do I download the Microsoft word on my Hp probook
    8·2 answers
  • Trish has bought a new computer that she plans to start working on after a week. Since Trish has not used computers in the past,
    10·1 answer
  • Assume n represents the number of inputs. The possible number of states within a truth table can be calculated using which of th
    10·1 answer
  • Rachel typed two paragraphs and then realized she was in the wrong document. What steps should Rachel follow to quickly move the
    15·2 answers
  • If all the data in a database is not physically located in one place, it would be a(n _______ database.
    5·1 answer
  • Assume that a file contains students' ids, full names, and their scores (Assignments grade, quizzes grade,
    5·1 answer
  • How can you insert an image file in your word document?​
    12·1 answer
  • Zoe wants to post something controversial online, but then she remembers that employers may look at her social media when she st
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!