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]
2 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]2 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
__________(fill in the blank) in online education refer(s) to how online education impacts students of a specific economic group
amid [387]

Answer:

I believe it's accessibility

Explanation:

Because it makes the most sense

7 0
2 years ago
Alexandria works for a non-for-profit company that asks for donations to help the homeless people in her community. Recently the
irakobra [83]

Answer:

Option A.

Explanation:

7 0
3 years ago
What statement is accurate in regards to
lorasvet [3.4K]

The statement that is accurate in regards to sharing workbooks is that You must add the feature to the Quick Access Toolbar

<h3>What does a shared workbook implies?</h3>

The term connote the act of sharing an Excel file. Here, a person can give other users any form of access to the same document.

Sharing workbook is one that allow people to make any kinds of edits at the same time, which saves a person the trouble of keeping track of different versions.

Learn more about workbooks from

brainly.com/question/5450162

7 0
2 years ago
Which type of network treats all processors equally, and allows peripheral devices to be shared without going to a separate serv
Elis [28]
The correct answer is P2P or peer-to-peer servers.

Hope I helped ;)
7 0
3 years ago
program that initialises a vector with the following string values: “what” “book” “is” “that” “you” “are” “reading”.
Zanzabum

A program that initializes a vector with the following string values: “what” “book” “is” “that” “you” “are” “reading” are the usage of namespace std;int main().

<h3>What is a vector software program?</h3>

Vector images software program permits customers to layout and manages pc photos the usage of geometric and mathematical commands, instead of clicks and strokes as utilized in drawing software program. Vector photos created the usage of those applications may be scaled indefinitely with out dropping quality.

  1. #include
  2. #include
  3. #include
  4. the usage of namespace std;
  5. int main()
  6. ;
  7. vector::iterator it;
  8. for (it = vs.begin(); it != vs.end(); it++)
  9. string tmp;
  10. while (cin.get()!='n')
  11. for (it = vs.begin(); it != vs.end(); it++)
  12. }

Read more about the vector :

brainly.com/question/25705666

#SPJ1

3 0
1 year ago
Other questions:
  • Which software application should be used to create a sales pitch to a group of people? Database Email Presentation Word process
    9·1 answer
  • ​What file system below does not support encryption, file based compression, and disk quotas, but does support extremely large v
    10·1 answer
  • The ________________ command tests connectivity by sending an echo request to a remote computer.
    14·1 answer
  • Which of these forms of multimedia would most likely contain both music and text:
    14·1 answer
  • What is the most important for you to choose before you build a network?
    7·1 answer
  • Different network devices function at different network communication layers, depending on their purpose. Using the TCP/IP model
    5·1 answer
  • How many ways do advertisers determine target audiences ??????
    15·1 answer
  • Suppose that the host with IP address 10.0.1.19 sends an IP datagram destined to host 128.119.160.183. The source port is 3324,
    7·1 answer
  • How to convert meters to centimeters in c programming​
    8·1 answer
  • February 1995, Kevin Mitnick was arrested. While on parole was he allowed to have a phone or computer?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!