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
Point out the correct statement.
NeTakaya

Answer:

Option D is correct.

Explanation:

Cassandra labeling information with such a gravestone indicates should restart transmitting an erase request to such a duplicate that had been down earlier of deletion.

Cassandra may not instantly delete information labeled for removal from disc the removal of identified information takes place throughout compaction a deleted section may reappear when a maintenance is never regularly carried out.

4 0
3 years ago
What is the name for the individual sections of the ribbon in PowerPoint 20162
Julli [10]

Answer:

Tabs

Explanation:

The ribbon contains the tabs. The tabs contain the command groups which hold commands

IF THIS HELPS PLEASE MARK THIS ANSWER AS BRAINLIEST

6 0
3 years ago
Suppose you are an ISP that owns a / 22 IPv4 address block. Can you accommodate requests from six customers who need addresses f
lisabon 2012 [21]

Answer:

It is not possible.

Explanation:

In this example, we need to accommodate 473 computers for six clients that are 473 IP addresses.

For this request just we have /22 IPv4 address blocks, this mean

22 red bits 11111111111111111111110000000000 <--- 10 host bits

We must increase red bits to 25, we need these 3 bits to create 6 sub red, in this case, 2^3 = 8 sub red.

Why did we ask 3 bits? Because if we ask only 2, 2^2 = 4, and we need 6 sub red.

25 red bits 11111111111111111111111110000000 7 host bits

In this case, we need more than 260 computers, but just we have 7 bits, this means.

2^7 = 128 and just one customer needs 260, for that is impossible.

7 0
3 years ago
Which of the following is an open-source web browser?
rosijanka [135]
That answer would be internet explorer
8 0
3 years ago
Read 2 more answers
What does "ttyt" stand for?
EastWind [94]
TTYT stands for "talk to you tomorrow".
6 0
3 years ago
Read 2 more answers
Other questions:
  • What are the 6 external parts of a computer
    14·1 answer
  • One of the most famous ___ licenses is gpl, which ensures that a particular program remains free to distribute and allows its co
    10·1 answer
  • What is one example of technology influencing health​
    9·1 answer
  • Explain the nature of documents that can be suitable for mergin
    12·1 answer
  • With the ease of the Internet, it is not uncommon for individuals to copy skills from resume templates to make themselves look m
    9·1 answer
  • In ________ for final fields and methods the value is assignedlater but in ______ you assign the value during declaration.
    15·1 answer
  • When you're working with a word processing document and you press the DEL Key what happens
    7·2 answers
  • Joel has left his computer unattended while answering a phone call. A TV repairer in his house tries to surf through the applica
    13·1 answer
  • Need the answer ASAP!!!
    14·1 answer
  • (Synchronized threads) Write a program that launches 1000 threads. Each thread adds a random integer (ranging from 1 to 3, inclu
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!