Reverse String in Java
Here you will get and learn Reverse String in Java Programming. To make this program first we will take an input string from the user, reverse the string using following method, and print the result.
Reverse String in Java Program Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import java.util.*; public class ReverseString { public static void main(String args[]) { String str, revStr = ""; Scanner in = new Scanner(System.in); System.out.print("Enter a string : "); str = in.next(); for (int i = str.length() - 1; i >= 0; i--) { revStr = revStr + str.charAt(i); } System.out.println("Reverse String is "+revStr); } } |
Output
Check out our other Java Programming Examples