Java program to check whether a given string is a palindrome
Codeaft.java
importjava.util.Scanner;classCodeaft{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
codeaft@codeaft:~$ javac Codeaft.java codeaft@codeaft:~$ java Codeaft
———————————————————————————————————————————
Program to check string is palindrome | not
———————————————————————————————————————————
Enter the string RADAR
RADAR is a palindrome
———————————————————————————————————————————
codeaft@codeaft:~$ javac Codeaft.java codeaft@codeaft:~$ java Codeaft
———————————————————————————————————————————
Program to check string is palindrome | not
———————————————————————————————————————————
Enter the string WIN
WIN is not a palindrome
———————————————————————————————————————————
codeaft@codeaft:~$
Dear User, Thank you for visitng Codeaft. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.