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 :: what is minecraft default render distance 
Java :: could not find or load main class org.apache.catalina.startup.bootstrap caused by: java.lang.classnotfoundexception: org.apache.catalina.startup.bootstrap 
Java :: logger output to console twice java 
Java :: Java Public Access Modifier package two 
Java :: ordenar numeros java 
Java :: why use var in java 
Java :: missingWords 
Java :: find namestart with name using strim in java 
Java :: java optional input for funktions 
Java :: how to write 1,2,3,4.... in java 
Java :: run jar with logback config file 
Java :: java singly linked list example 2 res 
Java :: how to refresh activity intent in android 
Java :: java page setup 
Java :: check whether an entry in hashmap is deleted in java 
Java :: thread Exemple 
Java :: example of throws clause in method 
Java :: java division int by 0 
Java :: clear array in java 
Java :: for loop in how to call class in android studio 
Java :: bukkit java get max players 
Java :: java byte array to blob 
Java :: if statement with string java 
Java :: java abstract class 
Java :: java program to print vowels in a string 
Java :: java union type 
Java :: get the logged in user java 
Java :: java string copy characters 
Java :: partioning operation Java 
Sql :: reset ids in mysql 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =