package recursion1;

/*
 * Given a string, compute recursively (no loops) a new string where all the
 * lowercase 'x' chars have been changed to 'y' chars.
 * 
 * changeXY("codex") -> "codey"
 * changeXY("xxhixx") -> "yyhiyy"
 * changeXY("xhixhix") -> "yhiyhiy"
 */

public class ChangeXYTest {
    public static void main(String[] args) {
		ChangeXYTest test = new ChangeXYTest();
		System.out.println(test.changeXY("codex"));
		System.out.println(test.changeXY("xxhixx"));
		System.out.println(test.changeXY("xhixhix"));
	}
    
    public String changeXY(String str) {
        if (str.indexOf('x') < 0) {
            return str;
        } else {
            int index = str.indexOf('x');
            if (index < str.length() - 1) {
                str = str.substring(0, index) + 'y' + str.substring(index + 1);
                return changeXY(str);
            } else {
                str = str.substring(0, index) + 'y';
                return changeXY(str);
            }
        }
    }
}
@@ -170,24 +170,25 @@
 XY(%22codex%22) 
+-
 -%3E %22codey%22%0A 
@@ -204,24 +204,25 @@
 Y(%22xxhixx%22) 
+-
 -%3E %22yyhiyy%22%0A
@@ -244,16 +244,17 @@
 ixhix%22) 
+-
 -%3E %22yhiy
@@ -992,8 +992,9 @@
 %0A    %7D%0A%7D
+%0A

Update ChangeXYTest.java