?

Algorithms & Data Structures

Free Version

Upgrade subject to access all content

Moderate

Exploiting the Recursive Structure of Strings

ALGOR-7ZT31E

You are provided with the following recursive function, which takes a String as input and returns a new String as a result:

public String modifyString(String s) {
    int length = s.length();

    if(length == 0)
        return "";

    return s.charAt(length - 1) + modifyString(s.substring(0, length - 1));
}

To test this function, you run the following command:

System.out.print(modifyString("Hello world!"));