Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

reverse string using recursion java with explanation

public class Test {

    private static int i = 0;

    public static void main(String args[]) {
        reverse("Hello");
    }

    public static String reverse(String str) {
        int localI = i++;
        if ((null == str) || (str.length()  <= 1)) {
            return str;
        }
        System.out.println("Step " + localI + ": " + str.substring(1) + " / " + str.charAt(0));
        String reversed = reverse(str.substring(1)) + str.charAt(0);

        System.out.println("Step " + localI + " returns: " + reversed);
        return reversed;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: kotlin string interpolation 
Java :: Loop Structure in Java 
Java :: java launch exe 
Java :: binary to integer in java 
Java :: declare array with values java 
Java :: java how to print a string[] 
Java :: String by byte array in java 
Java :: Error inflating class ImageView 
Java :: euclids algoritm java gcd 
Java :: java ioexception 
Java :: jframe visible 
Java :: android localdatetime 
Java :: inline arraylist initialization java 
Java :: Diamond pattern program in java 
Java :: java double format 
Java :: calling method in java 
Java :: action bar message spigot 1.8 
Java :: opacity in android studio 
Java :: java print hello world 
Java :: larger number in java than long 
Java :: java get number of threads 
Java :: string to byte array java 
Java :: changer version java terminal 
Java :: java numbers 
Java :: lambda comparator java 
Java :: iterable interface in java 
Java :: java get bigger int 
Java :: java find all of letter in string 
Java :: how to create an action listener in java 
Java :: how to print something in java 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =