Created
June 2, 2018 02:37
-
-
Save thmain/e720d97d83e675ba88998f86137b28e9 to your computer and use it in GitHub Desktop.
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 ReverseString { | |
public String reverse(String input){ | |
if(input.isEmpty()) | |
return input; | |
//else put the character at the beginning to the end | |
//make a recursive call | |
return reverse(input.substring(1))+input.charAt(0); | |
} | |
public static void main(String[] args) { | |
ReverseString r = new ReverseString(); | |
String input = "tutorial horizon"; | |
String reversedString = r.reverse(input); | |
System.out.println("Original String: " + input); | |
System.out.println("Reversed String: " + reversedString); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment