Answers for "reverse string using recursion"

3

reverse string using recursion java with explanation

public static String reverse(String str) {
    if ((null == str) || (str.length() <= 1)) {
        return str;
    }
    return reverse(str.substring(1)) + str.charAt(0);
}
Posted by: Guest on May-19-2020
0

Recursive reverse string

function reverse (str) {
    if (str === "") {
        return "";
    } else {
        return reverse(str.substr(1)) + str.charAt(0);
    }
}
Posted by: Guest on September-17-2021
0

reverse string with recursion

function reverse(string) {
  // Base case
  if (string.length < 2) return string;
  // Recursive case
  return reverse(string.slice(1, string.length)) + string[0];
}
Posted by: Guest on October-27-2021
0

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;
    }
}
Posted by: Guest on May-19-2020

Code answers related to "reverse string using recursion"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language