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
Why is Touchpad used in the laptop computer​
Ber [7]

Answer:

in controlling the mouse or cursor

Explanation:

as is it known tha a cursor is a poniting device. and the only way to control it without a mouse is the touchpad

3 0
3 years ago
Jacek has just started a new job as a sales clerk, and his first task is to create a new sales invoice. Which Microsoft software
g100num [7]

Answer:

Microsoft Excel

Explanation:

Microsoft Excel is a Microsoft application package. It is a spreadsheet application used to analyse and manipulate data. It has columns which are referred to fields and rows also known as records.There are various features in excel that used to create statistical and graphical esctasies and data presentations.

It can be used to create template for CVs/resumes, Bank draft, receipts and invoice etc.

5 0
3 years ago
When considering the purchase of a major software application, managers need to also consider the following potential downside:
Anastasy [175]

Answer:

The answer is B.The package seldom totally fits the company's needs

Explanation:

7 0
4 years ago
Al thecnology can do all the following except ​
ololo11 [35]

Answer:

D.

Explanation:

4 0
3 years ago
To create a digital signature, two steps take place that result in the actual signature that is sent with data. In the first ste
Ket [755]

Answer: Integrity verification of message.

Explanation:  Digital signature is used for the security purpose of the documents by the encryption technique such as passwords etc.The signature is created electronically for a digital document protection.The document is authenticated if correctly signed by the user/signer .

The collection of algorithms that are encrypted verifies the authenticity while being transferred if document content does not get tampered.This is the verification of integrity of the message sent from the sender to the signer.

4 0
3 years ago
Other questions:
  • Edhesive assignment 4 student schedule python
    10·2 answers
  • Define cyber law and cyber crime with examples.​
    11·1 answer
  • A typical item in a plan of procedure includes the name of the part of the ______ to
    5·1 answer
  • Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and s
    12·1 answer
  • I need help ASAP Asap asap!!!
    11·1 answer
  • What is thought to have caused the extinction of the dinosaurs?
    13·1 answer
  • What do the stapedius and gluteus maximus have in common?<br> this is a science question
    12·2 answers
  • Enlist the advantages of data consolidation in a spreadsheet
    10·1 answer
  • You have studied graphic design, advanced math, and programming, and you
    13·1 answer
  • Type the correct answer in the box. Spell all words correctly. Which language should you use to add functionality to web pages?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!