public class recursiveReverse {
public static String reverse(String str){
if (str == null) {
return null;
}
if (str.length() <= 1) {
return str;
}
return reverse(str.substring(1)) + str.charAt(0);
}
public static void main(String[] args) {
reverse("car");
}
}
I get to the first time the if (str.length() <= 1) returns true, then I get lost.