Recursive String Reversal
What is the output when the program runs?
public class RecursiveReverse {
public static String reverse(String s) {
if(s.length() <= 1) {
return s;
}
return reverse(s.substring(1)) + s.charAt(0);
}
public static void main(String[] args) {
System.out.println(reverse("hello"));
}
}
A
hello
B
lleho
C
oellh
D
olleh
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE