Java program to reverse a given string using the reverse method
GD.java
importjava.util.Scanner;classGD{publicstaticvoidmain(Stringargs[]){Strings;Scannersc=newScanner(System.in);System.out.println("———————————————————————————————————————————");System.out.println("Program to reverse the given string");System.out.println("———————————————————————————————————————————");System.out.print("Enter the string ");s=sc.nextLine();Stringr=newStringBuffer(s).reverse().toString();System.out.println("\nThe reverse string is "+r);System.out.println("———————————————————————————————————————————");}}
Output
godarda@gd:~$ javac GD.java godarda@gd:~$ java GD
———————————————————————————————————————————
Program to reverse the given string
———————————————————————————————————————————
Enter the string Hello, World!
The reverse string is !dlroW ,olleH
———————————————————————————————————————————
godarda@gd:~$
Dear User, Thank you for visitng GoDarda. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.