// Goals of this code to teach recursion
// Review:  static methods, polymorphic methods, debugging methods

import java.io.*;

public class Reverse {
	

// reverse a string?  could also use a stack! simpler to use recursion
public static String reverse(String s) {
	int len = s.length();
    
    if (len <= 1) {// base case
      // System.out.println("base case with only one letter left: " + s);
      return s; // base case
    }
    else {
      char lastChar = s.charAt(len-1);
      String remainder = s.substring(0, len-1);
      // System.out.println(lastChar);
      return lastChar + reverse(remainder);
    } 
}
	

	

public static void main ( String[] args ) {
	
	// reverse string example
	// how would we do this iteratively?
	String mystr = "scoobydoo";
	String reversed = reverse(mystr);
	System.out.println(mystr + " in reverse is:  " + reversed); 
	
}

}
	
