Enter any string as input. Now we use for loops and if-else conditions along with equalsIgnoreCase() method to conclude whether the entered string is palindrome or not.
Here is the source code of the Java Program to Check whether a String is a Palindrome. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Palindrome
public static void main(String args)
String a, b = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter the string you want to check:");
a = s.nextLine();
int n = a.length();
for(int i = n - 1; i >= 0; i--)
b = b + a.charAt(i);
System.out.println("The string is palindrome.");
System.out.println("The string is not palindrome.");
$ javac Palindrome.java $ java Palindrome Enter the string you want to check:NeveroddorEVen The string is palindrome.
Sanfoundry Global Education & Learning Series – 1000 Java Programs.