package recursion1;

/*
 * Given a string, compute recursively (no loops) the number of times
 * lowercase "hi" appears in the string. 
 * 
 * countHi("xxhixx") -> 1
 * countHi("xhixhix") -> 2
 * countHi("hi") -> 1
 */

public class CountHiTest {
    public static void main(String[] args) {
		CountHiTest test = new CountHiTest();
		System.out.println(test.countHi("xxhixx"));
		System.out.println(test.countHi("xhixhix"));
		System.out.println(test.countHi("hi"));
	}
    
    public int countHi(String str) {
        if (str.length() <= 1) {
            return 0;
        } else {
            if (str.substring(0, 2).equals("hi")) {
                return 1 + countHi(str.substring(1));
            } else {
                return countHi(str.substring(1));
            }
        }
    }
}
@@ -154,16 +154,17 @@
 xhixx%22) 
+-
 -%3E 1%0A * 
@@ -182,16 +182,17 @@
 ixhix%22) 
+-
 -%3E 2%0A * 
@@ -205,16 +205,17 @@
 i(%22hi%22) 
+-
 -%3E 1%0A */
@@ -788,8 +788,9 @@
 %0A    %7D%0A%7D
+%0A

Update CountHiTest.java