Java program to reverse a given string using charAt method
KW.java
importjava.util.Scanner;classKW{publicstaticvoidmain(Stringargs[]){Strings,r="";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();for(inti=s.length()-1;i>=0;i--){r=r+s.charAt(i);}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.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?