Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReverseRecursion {
- public static String reverseRecursively(String str) {
- if (str.length() < 2) {
- return str;
- } return reverseRecursively(str.substring(1)) + str.charAt(0);
- }
- public static void main(String args[]) {
- String str = "Ammar Al-Nasseri";
- System.out.println("Original String: " + str);
- System.out.println("Reversed String: " + reverseRecursively(str));
- } // End Main
- } // End Class
Add Comment
Please, Sign In to add comment