I hate to abuse SO for homework but I'm in a pickle. Basically, my instructor wants me to do this:
Write a recursive method to print a String backwards.
- The method header is: public void printBackwards1(String s)
- The print statement must be before the recursive call.
- The method should not alter or reverse the String, only print it backwards.
After that, they want me to do the same thing but have the print statement after the call.
I'm stumped. I already whipped up a normal-person recursive method:
public static String reverseString(String input) {
if(input.equals("")) {
return input;
}
else {
return(reverseString(input.substring(1)) + input.substring(0, 1));
}
}
But the print stuff has me scratching my head. Thanks in advance!