Java program to reverse a given string using the reverse method
KW.java
importjava.util.Scanner;classKW{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
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to reverse the given string
———————————————————————————————————————————
Enter the string Hello, World!
The reverse string is !dlroW ,olleH
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.