Java Online Compiler
Example: String Reverse in Java using Function
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// String Reverse in Java using Function import java.util.Scanner; public class Main { // It will reverse the input string public static void revString(String x) { for (int i=(x.length()-1); i>=0; i--) { System.out.print (x.charAt(i)); } } // 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); System.out.println("\n"); } }
hello example
Output
Clear
ADVERTISEMENTS