X1661: Replace space with underscore

Description

Given a string, compute recursively a new string where all spaces in the original one are replaced by an underscore (_).

So given "hello world", return "hello_world".

Constraints

  • You cannot use the following methods from the String class: indexOf, lastIndexOf, contains, endsWith, startsWith, matches, replace, nor replaceAll.

Documentation

Examples:

replaceWUnderscore("hello world") -> "hello_world"
replaceWUnderscore("buenos dias") -> "buenos_dias"

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.