Having trouble with this c++ question. Write a recursive, string -valued functio
ID: 652093 • Letter: H
Question
Having trouble with this c++ question.
Write a recursive, string -valued function, 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
Explanation / Answer
String replace(String s){ if(s.length()<1) return s; String concat=s.charAt(0)==' '? "*" : s.charAt(0)+""; return concat+replace(s.substring(1)); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.