So for homework this weekend we're learning about recursion so that means the dreaded string reversal with recursion problems. I have a simple piece of code that is correctly performing the recursion (according to the debug mode in eclipse) but since (?? this is where I'm confused) I'm calling it from a a different area of the program, it just keeps going on infinitely until it crashes or overflows or whatever it's called.
public static void main(String[] args)
{
System.out.println(reversePrint("Hello"));
}
public static String reversePrint(String s)
{
if (s.length() <= 1)
return s;
return reversePrint(s.substring(1) + s.charAt(0));
}
I've been trying to Google-fu my way to figuring out why but I just can't, most sites explain recursion with pretty much the code I've written for the actual reversal of the string, but none seem to deal with any problems with getting it to print. I honestly don't know what I'm overlooking, been at this for a few hours, feels like I'm banging my head against a wall.