148k views
4 votes
Write a method that takes in a String and returns a new

string that replaces every instance of the letters k, a, r, e, l with two occurrences of
that letter.

For example.

moreKarelLetters("kaleidoscope")
would return

"kkaaleeidoscopee"
Hint : Strings have a method .contains(str) which returns a boolean
indicating if a given Strings contains another String.

This is in Java.

1 Answer

5 votes

Answer:

Is in the provided screenshot!

Step-by-step explanation:

Steps needed to solve this problem!

1) Take your input string and split it down into an array of each of its characters

2) Create a new string that you will use for your output

2) Go through each of your characters and check if they are equal to 'k' 'a' 'r' 'e' 'l'.

3) Add the letter onto the end of the new string, and if it is one of those letters, then add it on again!

4) Return the output string.

Write a method that takes in a String and returns a new string that replaces every-example-1
User Pureofpure
by
4.4k points