String Reverse with Recursion

String Reverse with Recursion
SOURCE : StringRecursiveReversal.java


public class StringRecursiveReversal {

static String reverse = "";

public static String reverseString(String str){

if(str.length() == 1){
return str;
} else {
reverse += str.charAt(str.length()-1)
+reverseString(str.substring(0,str.length()-1));
return reverse;
}
}

public static void main(String a[]){


//StringRecursiveReversal srr = new StringRecursiveReversal();
System.out.println("Result: "+reverseString("OnlineCodeGeek"));
}
}

INPUT

OnlineCodeGeek



OUTPUT

Result: keeGedoCenilnO







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment