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
JAVA
Umnica [9.8K]

import java.util.Scanner;

public class JavaApplication58 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a positive integer:");

       String num = scan.nextLine();

       for (int i = num.length()-1; i >=0; i--){

           System.out.println(num.charAt(i));

       }

       

   }

   

}

I hope this helps!

5 0
3 years ago
Why won't my laptop charge?
yarga [219]

Answer:

I had a similar problem. I would suggest consulting someone professionally because thats what I had to do. I really dont know why it does that

4 0
3 years ago
What type of culture is computer hardware?
skad [1K]
Culture, the software, is learned to trigger evolution to a new type of society, they may all.
6 0
2 years ago
Read 2 more answers
In PowerPoint _____ management is extremely important and you must keep track of what links, files, and programs are placed in w
harkovskaia [24]

Answer: File

Explanation:

In PowerPoint _file_ management is extremely important and you must keep track of what links, files, and programs are placed in which folders.

File Management is extremely important because it is necessary for effective system administration.

A good file management system in powerpoint makes compactness, data retrieval and editing achieveable.

6 0
2 years ago
When you tell an acquaintance your telephone number, you do not recite the digits one by one at a constant rate, as in "3, 3, 7,
yKpoI14uk [10]

Answer:

chunking and short-term is the correct answer of this question.

Explanation:

chunking is a strategy to enhance a short-term memory.

Chunking is an method used to separate larger numbers that can not be psychologically separated.Chunking is the grouping of words in one sentence into short, important phrases. A chunk is the material segment that is used in many graphical formats, such as PNG etc.

Short-term memory is the knowledge a person is considering or is conscious of. This is also called healthy or main memory.

3 0
3 years ago
Other questions:
  • In Linux Operating System, what file extension is used forexecutable files?
    6·1 answer
  • Which command can be used to manually add a package to the driver store?
    13·1 answer
  • Tim has an old server computer that his company uses as a backup. One of the hard drives has gone bad and needs to be replaced.
    13·1 answer
  • What technique creates different hashes for the same password? ccna routing protocols final answers?
    7·1 answer
  • You want to enable nap so that all portal computers using wireless connections have an active firewall. which type of enforcemen
    11·1 answer
  • Define additional characteristics such as font weight or style for an html tag
    5·1 answer
  • Girls question <br> who wants to go out ;p
    11·2 answers
  • I found a brand-new charger wire still in its plastic package, but it's six years old and has never been used. Is it safe to use
    9·1 answer
  • In which of the following movies, multimedia's special effect is used ? *
    8·2 answers
  • If a person communicates indirectly and attaches little value to
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!