Java program to check whether a given string is a palindrome
KW.java
importjava.util.Scanner;classKW{publicstaticvoidmain(Stringargs[]){Strings,r="";Scannersc=newScanner(System.in);System.out.println("———————————————————————————————————————————");System.out.println("Program to check string is palindrome | not");System.out.println("———————————————————————————————————————————");System.out.print("Enter the string ");s=sc.nextLine();intl=s.length();for(inti=l-1;i>=0;i--)r=r+s.charAt(i);if(s.equals(r))System.out.println("\n"+s+" is a palindrome");elseSystem.out.println("\n"+s+" is a not palindrome");System.out.println("———————————————————————————————————————————");}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to check string is palindrome | not
———————————————————————————————————————————
Enter the string RADAR
RADAR is a palindrome
———————————————————————————————————————————
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to check string is palindrome | not
———————————————————————————————————————————
Enter the string WIN
WIN is not a palindrome
———————————————————————————————————————————
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, you need to install apk manually. Would you like to get the app? Minimum Requirement(s): Android 10