answer.
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]
1 year 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]1 year 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
Can you find the reason that the following pseudocode function does not return the value indicated in the comments? // The calcD
Alexus [3.1K]

Answer:

see explaination

Explanation:

Function Real calcDiscountPrice(Real price, Real percentage) // Calculate the discount.

Declare Real discount= (price * percentage) / 100.0 // Subtract the discount from the price.

//dividing by 100.0 because of % concept

Declare Real discountPrice = price - discount // Return the discount price.

Return discount End Function

5 0
1 year ago
Choose the response that best completes the following statement.
lisabon 2012 [21]
I am guessing. My guess is code.
7 0
1 year ago
Read 2 more answers
To what extent are the following computer systems instances of artificial intelligence:
ss7ja [257]

Answer: Supermarket bar code scanners and Voice-activated telephone menus are not instances of artificial intelligence

Explanation:

(a)Supermarket bar code scanners are only able to read the code however they are not able to perform any kind of machine learning techniques to be able to learn a sequence from the codes. As machine learning is a important part of artificial intelligence (AI) so they are not instances of AI. Similarly for Voice-activated telephone menus they could only display and cannot perform any intelligent task.

Web search engines and Internet routing algorithms are very dynamic and intelligent in processing and retrieving information to the end user.

So they are instances of AI.

8 0
1 year ago
The OSHA Workplace Poster 3165 is optional for workplaces.<br> A) True<br> B) False
bezimeni [28]

Hello, your answer is ready.


Answer: A) True



Best of luck!


~

Your pal papaguy

5 0
2 years ago
Read 2 more answers
Algorithmic Complexity: what is the asymptotic complexity (Big-O) of each code section? Identify the critical section of each.\
AleksandrR [38]

Answer:

Check the explanation

Explanation:

1) f(n) = O( 1 ), since the loops runs a constant number of times independent of any input size

there is no critical section in the code, as a critical section is some part of code which is shared by multiple threads or even processes to modify any shared variable.This code does not contain any variable which can be shared.

2) f(n) = O( log n! ), the outer loop runs for n times, and the inner loop runs log k times when i = k,ie the total number of print will be – log 1 + log2 +log3 +log4+…...+ log n = log (1 . 2 . 3 . 4 . ……. . n ) =log n!

there is no critical section in the code, as a critical section is some part of code which is shared by multiple threads or even processes to modify any shared variable.This code does not contain any variable which can be shared.

Note : Log (m *n) = Log m + Log n : this is property of logarithm

3) f(n) = O( n^2 ), since both outer and inner loop runs n times hence , the total iterations of print statement will be : n +n+n+…+n

for n times, this makes the complexity – n * n = n2

there is no critical section in the code, as a critical section is some part of code which is shared by multiple threads or even processes to modify any shared variable.This code does not contain any variable which can be shared.

4 0
2 years ago
Other questions:
  • How did josh norman and mike keller provide coverage of katrina?
    9·2 answers
  • Which selections are possible for controlling the start time of audio playback? Check all that apply. Automatic Rewind when done
    10·1 answer
  • Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE p
    8·1 answer
  • Which of the following provides a suite of integrated software modules for finance and accounting, human resources, manufacturin
    15·1 answer
  • 15) The codes for class Hotel has been defined in two separate files Hotel.h, and Hotel.cpp. Which of the following statements i
    12·1 answer
  • Justify the statement "The same job title can have different job roles and different qualification criteria in different organiz
    7·1 answer
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
  • Assume you have a project with seven activities labeled A-G (following). Derive the earliest completion time (or early finish-EF
    15·1 answer
  • If Maya wants to access a view that would control multiple slides within a presentation, which view should she utilize? Master v
    9·1 answer
  • Taylor and Rory are hosting a party. They sent out invitations, and each one collected responses into dictionaries, with names o
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!