Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@devmike01
Last active June 16, 2022 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devmike01/d2c0ba7193461285b368ef293f6310be to your computer and use it in GitHub Desktop.
Save devmike01/d2c0ba7193461285b368ef293f6310be to your computer and use it in GitHub Desktop.
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