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
Which type of database program is Microsoft Access 2016?
nadya68 [22]

Answer:

O relational

Explanation:

If I'm wrong I'm so so sorry! But form my research it keeps saying its relational.

If I'm right please give me brainliest I really need it to level up so please help me!

If you don't know how to give brainliest there should be a crown underneath my answer you just have to click it.

Thank you and have a wonderful night,morning,afternoon/day! :D

6 0
2 years ago
Read 2 more answers
After you design and write your help-desk procedures to solve problems, what should you do next?
vichka [17]

<em>After you design and write your help-desk procedures to solver the problem, the next step would be, testing and implementation. </em>

<em> </em>

<em>Basically, in any problem-solving process, after planning and designing the solutions, the next process that should be implemented next is: testing and implementation. In the testing phase, staff and employees would implement the solution softly, meaning everything is not advertised yet and not formal yet. They would execute the plan and design and would evaluate if it is really effective. A documentation will prepare as the basis of the evaluation. After the testing, the project team would determine if the offered solution is possible or if there are more improvements to make.</em>

7 0
3 years ago
I need help with my homework:
Likurg_2 [28]

Answer:

You need to order 11100 pizzas.

Explanation:

A couple of assumptions here.

Each pizza has 12 slices.  Each guest will eat 4 slices (1/3 of a pizza).

83 * 1/3 = 28 pizzas

28 = 11100

4 0
2 years ago
HELP ASAP!!!! PLEASE !!! What information does the Media Access Control (MAC) on a network card provide?
sladkih [1.3K]

Answer:

3. the company that installed the network card into the computer's motherboard

3 0
3 years ago
Read 2 more answers
a savings account earns 4.8% apr, compounded monthly, so it earns .4% each month. travis has 1500 in the account now. if he depo
algol13

The answer is $8.00 on apex ;)

6 0
3 years ago
Read 2 more answers
Other questions:
  • The BIOS feature that enables a hard drive to read or write several sectors at a time is called what?
    5·1 answer
  • When saving a document or drawing, you determine the destination folder in which the file will be saved by?
    6·1 answer
  • What OS is most commonly used by businesses? Linux Macintosh Microsoft Windows
    11·1 answer
  • Which one of the following business names would be rated Incorrect for name accuracy? Answer McDonald's McDonald's H&amp;M McDon
    14·1 answer
  • Your company has purchased another company that also uses Windows Server 2016 and Active Directory. Both companies need to be ab
    11·1 answer
  • The following statement calls a function named half, which returns a value that is half
    8·1 answer
  • What is the next line?
    7·1 answer
  • A line graph is a great tool for showing changes over time. Why is a line graph better than other graphs at showing this type of
    6·1 answer
  • THIS IS TIMED PLS HURRY UP
    7·1 answer
  • Write a C++ line of code to declare a variable of type “double” that signifies the average of student grades, then initialize th
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!