Exercise
Reverse, Recursive
Objetive
Create a program that uses recursion to reverse a string of characters (for example, from "Hello" it would return "olleH").
Example Code
public class Main
{
public static String Reverse(String text)
{
if (text.length() <= 1)
{
return text;
}
char firstLetter = text.charAt(0);
String rest = text.substring(1);
return Reverse(rest) + firstLetter;
}
public static void main(String[] args)
{
System.out.println(Reverse("Juan"));
}
}