185,686 views
26 votes
26 votes
write a recurseive string-returned function replace that accepts a string and returns a new string consisting of the original string with each blank replace with an asterisk

User Nate Zaugg
by
2.9k points

1 Answer

18 votes
18 votes

Answer:

Write a recursive, string -valued method, replace, that accepts a string and returns a new string consisting of the original string with each blank replaced with an asterisk (*)

Step-by-step explanation:

Replacing the blanks in a string involves: Nothing if the string is empty Otherwise: If the first character is not a blank, simply concatenate it with the result of replacing the rest of the string If the first character IS a blank, concatenate an * with the result of replacing the rest of the string

User Vladimir Vargas
by
3.6k points