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
As a photographer, what will be the driving force behind everything that you produce?
GREYUIT [131]

Answer:

You have to like it to be successful in photography.

Explanation:

8 0
2 years ago
Def sum_divisors(n): sum =1 # Return the sum of all divisors of n, not including n x=int(n**0.5) for i in range(2,(x//1)+1): if
Novosadov [1.4K]

Answer:

This is a python program that counts the number of divisors of a given number and calculates the sum of the divisors.

Explanation:

The first line defines a function "sum_divisors" with an argument "n". The square root of the argument is converted to integer and assigned to the variable "x", then a for loop is used to iterate through the range 2 to the calculated nth number of divisors in the argument.The return keyword returns the sum value.

The function is called with several arguments and printed with the print function.

6 0
2 years ago
PLEASE HELP ME Jimmy and his friends are creating a rock band and have decided to turn his garage into a recording studio. He wa
Tems11 [23]

Answer:

D.  a studio monitor

Explanation:

A studio monitor is an electrical equipment that is used to enhance the quality of sound or music. It work like a speaker that can be used professionals to record audio songs, to make films and some other applications with good quality. It is usually used in studios where producer must ensures that the quality of music. As in music industry the quality of music depends on the quality of instrument used for the purpose of recording.

<em>This is the reason that, Jimmy and his friends should choose a Studio Monitor to achieve the most accurate sound quality.</em>

6 0
2 years ago
What is an embedded system. Give examples
IRINA_888 [86]

Answer:

An embedded system is a part of a larger system which has either one or a limited number of dedicated functions.

It doesn't require much power to run and is cheap to make and design.

Explanation:

Examples include: cars, microwaves, traffic lights, washing machines, phones etc

6 0
3 years ago
What's the biggest security issue with using social networking sites to market your listings?
Savatey [412]

The biggest security issue with using social networking sites to market your listings is Criminals may use social networking sites to identify your personal data.

<h3>What is a social marketing site?</h3>

A social marketing site is a site where people from around the world are connected in one place and share their thoughts and photos and other data.

The social sites are on the internet and there is a chance of stealing data and it identity theft, phishing, online predators, internet fraud, and other cybercriminal attacks are also some risks.

Thus, the largest security concern with using social networking sites to sell your listings is that thieves could use these sites to find personal information about you.

To learn more about social marketing sites, refer to the link:

brainly.com/question/15051868

#SPJ4

6 0
1 year ago
Other questions:
  • Sean is white hat hacker, who is demonstrating a network level session hijack attacks and as part of it, he has injected malicio
    6·1 answer
  • Hello, please help write code in C++. Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go nort
    12·1 answer
  • For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, D
    5·1 answer
  • An Einstein Analytics team wants to create a dashboard that displays values from an external, on-premise Oracle Database. What a
    7·1 answer
  • A device that protects electronic equipment from an increase in power, but not a decrease or outage is a ___.
    12·1 answer
  • What command would you use to add a file to an e-mail message?
    15·2 answers
  • The information provided in text aids can help us to understand a text’s content before we even read it.
    8·1 answer
  • Which category does this fall in identity theft​
    6·1 answer
  • Write a program that will add up the series of numbers: 99, 98, 97… 3, 2, 1. The program should print the running total as well
    13·1 answer
  • Complete the statement below with the correct term.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!