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 python keyword______.
Cerrena [4.2K]

Answer:

cannot be used outside of its intented purpose

Explanation: python keywords are special reserved words that have specific meanings and purposes and can't be used for anything but those specific purposes

8 0
3 years ago
The director of HR realizes that the KSAs currently used for hiring entry-level engineers are outdated. In order to establish wh
Vaselesa [24]

Answer:

Job analysis

Explanation:

The HR should preferably use job analysis.

6 0
3 years ago
I need help pleaseeee
MrRissso [65]

Answer:

Explanation:

I  ....

6 0
2 years ago
Why would a network administrator want to filter certain ports when capturing data such as FTP traffic
hjlf

Answer:

To avoid receiving malware-infected files like spam.

Explanation:

Hackers use malware to gain unauthorized access to company files and information for personal gain. Files infected by the malware can infect other systems or files. There are various types of malware namely; virus, trojan horse, worm, spyware, ransomware, adware etc.

5 0
2 years ago
Which part of project management involves determining possible risks?
stira [4]
Resources :) You’re welcome
7 0
2 years ago
Read 2 more answers
Other questions:
  • A rectangular range of cells with headings to describe the cells' contents is referred to as a
    9·1 answer
  • George and Miguel want to know more about their local and online competitors and about the retail industry. What is the best way
    9·1 answer
  • Objects falling through air experience a type of friction called.. A.terminal velocity B.air resistance C.rolling friction
    8·1 answer
  • What are some ways tables can be inserted into a document? Check all that apply.
    5·2 answers
  • How do i build a supercomputer.?
    11·1 answer
  • The requirement that each term in the objective function only contains a single variable is in a linear program is referred to a
    5·1 answer
  • How has information technology made piracy possible
    14·1 answer
  • • Open your Netbeans IDE and answer the following question
    5·1 answer
  • The arrows in this question indicated the determination of two attributes. For example, the arrow that goes ProductID to Product
    11·1 answer
  • The students of a college have to create their assignment reports using a word processing program. Some of the questions in thei
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!