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
Alexandra [31]
3 years ago
7

Write a method named removeDuplicates that accepts a string parameter and returns a new string with all consecutive occurrences

of the same character in the string replaced by a single occurrence of that character. For example, the call of removeDuplicates("bookkeeeeeper") should return "bokeper" .
Computers and Technology
1 answer:
Nitella [24]3 years ago
7 0

Answer:

//Method definition

//Method receives a String argument and returns a String value

public static String removeDuplicates(String str){

       //Create a new string to hold the unique characters

       String newString = "";

       

       //Create a loop to cycle through each of the characters in the

       //original string.

       for(int i=0; i<str.length(); i++){

           // For each of the cycles, using the indexOf() method,

           // check if the character at that position

           // already exists in the new string.

           if(newString.indexOf(str.charAt(i)) == -1){

               //if it does not exist, add it to the new string

               newString += str.charAt(i);

           }  //End of if statement

       }   //End of for statement

       

       return newString;   // return the new string

   }  //End of method definition

Sample Output:

removeDuplicates("bookkeeeeeper") => "bokeper"

Explanation:

The above code has been written in Java. It contains comments explaining every line of the code. Please go through the comments.

The actual lines of codes are written in bold-face to distinguish them from comments. The program has been re-written without comments as follows:

public static String removeDuplicates(String str){

       String newString = "";

       

       for(int i=0; i<str.length(); i++){

           if(newString.indexOf(str.charAt(i)) == -1){

               newString += str.charAt(i);

           }

       }

       

       return newString;

   }

From the sample output, when tested in a main application, a call to removeDuplicates("bookkeeeeeper") would return "bokeper"

You might be interested in
A company is looking for an employee to install new computers and integrate them into its existing network. Which computer field
Shkiper50 [21]
A. Network systems administrator
6 0
3 years ago
In a black box model are the customers told that they should be expecting to be haxked?
Licemer1 [7]
Uhhhhhhhhhhh maybe tbh i have noooo idea.
6 0
3 years ago
What does this map key show
jeka94

Answer: where is the map key? I don't see it

Explanation:

7 0
3 years ago
Media convergence is the result of the integration of the different media technologies. Please select the best answer from the c
AlladinOne [14]

This is true

We can simply put media convergence as the merging of previously distinct media technologies into one core technology or ecosystem. All it takes is separate ideas being smashed together to form one big idea. An example of media convergence is a smartphone. The smartphone is the technological convergence of communication. It can be used to communicate while functioning as a computer on which we share and view content. Before, this could have taken several devices to accomplish the above task individually.

7 0
4 years ago
Read 2 more answers
Need help please will mark brainliest
aleksklad [387]

Answer:

intranet

Explanation:

An intranet is a private network that you can't access outside the physical boundary of an organization

7 0
3 years ago
Other questions:
  • The index finger on your right hand types the _____.
    11·1 answer
  • Which of the following is NOT a logical operator (logical connective)?
    5·1 answer
  • I have a question about a hotel tv:
    10·1 answer
  • What changes do you need to a algorithm to compare 100 numberst
    7·1 answer
  • How to change default search engine in internet explorer 11?
    13·1 answer
  • You would like the user of a program to enter a customer’s last name. Write a statement thaUse the variables k, d, and s so that
    5·1 answer
  • To what type of user does he most likely have access? Jae is using a computer at the public library to do research she's able to
    9·1 answer
  • Select the correct answer from each drop-down menu
    6·2 answers
  • Is this right? I’m not sure
    15·1 answer
  • Help I will mark BRAINLIEST !<br> Explain looping as an invention strategy. Why is it helpful?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!