Ask Question
12 August, 19:59

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 (*) 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.

+5
Answers (1)
  1. 12 August, 20:13
    0
    Check the explanation

    Explanation:

    public String replace (String sentence) {

    if (sentence. isEmpty ()) return sentence;

    if (sentence. charAt (0) = = ' ')

    return '*' + replace (sentence. substring (1, sentence. length ()));

    else

    return sentence. charAt (0) + replace (sentence. substring (1, sentence. length ()));
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a recursive, string-valued method, replace, that accepts a string and returns a new string consisting of the original string with ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers