Write a recursive function, replace, that accepts a parameter containing a string value and returns another string value, the same as the original string except with each blank replaced by an asterisk "*".

Respuesta :

You should state what language you want your answer to be in before you ask programming questions. Here is what you're looking for in Java:

public static String replace(String str) {
    return str.replace(' ', '*');
}
fichoh

The function taken in an argument which is a string and gives an output of the same string with a asterisk (*) inserted inbetween each word. The program written in python 3 goes thus :

def replace(sentence):

#initialize a function named replace which takes in a single string sentence

sent = sentence.split()

#the sentence is split based on whitespace as a list of words which is attached to the variable called sent.

return '*'.join(sent)

Inbetween two words, a asterisk is appended using the join method.

print(replace('i am here'))

#A sample run of the function with an example is given and the output attached below.

Learn more : https://brainly.com/question/16403687

Ver imagen fichoh