Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple java code snippet which uses recursion to reverse any given string.
public class RecursionReverseString {
public static void main(String[] args){
String value = "abcdefghijk";
System.out.println(reverse(value.length()-1, value, ""));
}
public static String reverse(int l, String value, String r){
if(l <0 ){
return r;
}
r += String.valueOf(value.charAt(l));
return reverse(l-1, value, r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment