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
____ arguments may provide more control over the returned value.
OLga [1]
D. Absolute is the answer
3 0
4 years ago
What are the chances that we are living in a simulation? (Percentage)
harkovskaia [24]
Round about 95% Chance to living in a Simulation
5 0
3 years ago
Read 2 more answers
What is the maximum number of different codes that can be represented in 2 bytes?
olganol [36]
A two byte word has 16 bits, so there are 2^16 possible values.
5 0
3 years ago
Which of the following is the result of a query?
IgorLugansk [536]
I think the answer is A
6 0
3 years ago
5
Delvig [45]

Answer:

All of these answers

Explanation:

Leadership activities can be used to improve teamwork, further better communication in the workplace and develop teamwork.

Help you practice professionalism skills

Correct - Student leadership can help one with better communication, teamwork, planning, organization, taking charge - all very important life skills

Offer opportunities to participate in events outside of school, such as competitions

Correct - Student leadership can lead one to participate in events inside and outside of school, including competitions, service projects, fundraisers, and more.

Help build your resume

Correct - Many colleges and job applications look specifically for student leadership in the resume. Participating in student leadership will also help you win scholarships.

Have a lovely rest of your day! :)

5 0
2 years ago
Other questions:
  • When should an individual consider entering parenthood?
    5·1 answer
  • What are some types of vehicle technology advancements?
    5·1 answer
  • Write an algorithm that gets as input your current credit card balance, the total dollar amount of new purchases, and the total
    8·1 answer
  • Some in the security community argue that a lack of diversity is security vulnerability. For example, Firefox and Internet Explo
    6·1 answer
  • James would like to send a document he has saved on the hard drive to coworkers in Ireland, Brazil, and India. These coworkers h
    6·2 answers
  • Discuss the term business information SYSTEMS ​
    15·1 answer
  • Write a calculate_sq_inches_of_good_pizza function that accepts the diameter of a pizza and returns the area of the pizza minus
    7·1 answer
  • If someone you don’t know asks where you go to school, what should you do
    12·1 answer
  • How to hack a I'd Indian brainly bot​
    7·1 answer
  • 2. Cryptography relies on open standards - a protocol or standard that is publicly available. Why are open standards necessary
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!