Just did this one. Enter text and recursion method will reverse it.
Code:import java.util.Scanner; public class recursionDemo{ public static void main (String[] args){ Scanner scan = new Scanner (System.in); System.out.println("Enter text to reverse: "); String s = scan.nextLine(); reverse(s); } public static void reverse(String s){ if (s.length() == 1){ System.out.print(s); } else{ reverse (s.substring(1, s.length())); System.out.print(s.substring(0,1)); } } }




Reply With Quote