Java Method Recursion reverse String

Description

Java Method Recursion reverse String


public class Main {
   public static void main(String[] args) {
      System.out.println(reverse("ABCDEFG"));
   }/*w  w w  .ja v a  2 s . c o  m*/
   public static String reverse(String str) {
      if (str.length() <= 1) {
         return str;
      }
      return reverse(str.substring(1)) + str.substring(0, 1);
   }
}



PreviousNext

Related