In Java
For example, if the user were to input “Hello”. The out put would be :
olleH
I’m done.
import java.util.Scanner; public class ReverseStrings { public static void printReverse(String s) { if (s.length() == 0) { System.out.println("\nI'm done."); } else { System.out.print(s.charAt(s.length() - 1)); printReverse(s.substring(0, s.length() - 1)); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a string: "); String s = in.nextLine(); printReverse(s); } }
Get Answers For Free
Most questions answered within 1 hours.