Last active
June 16, 2022 21:03
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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