Java Online Compiler
Example: String Reverse in Java using Recursion
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// String Reverse in Java using Recursion import java.util.Scanner; public class Main { // It recursive function will print the characters on the right side public static int revString(String x, int l) { if (l>=0) { System.out.print (x.charAt(l)); l--; revString(x, l); } return 0; } // It's the driver function public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter a string to make reverse::\n"); String x=in.nextLine(); // It will print the final output System.out.print ("The reverse of the string is:: "); revString(x, x.length()-1); System.out.println("\n"); } }
hello example
Output
Clear
ADVERTISEMENTS