public static String rev(String s) {
if (s.length() <= 1) return s;
return rev(s.substring(1)) + s.charAt(0);
}
System.out.println(rev("abcd"));What is printed?
- Acheck_circle
dcba
- B
abc
- C
abcd
- D
dabc
Explanation
Each call moves the first character to the end of the recursively reversed remainder.