Palindrome String - Java Program

Q. Write a Java program to check if the string is palindrome or not.

Answer:

Palindrome is a word, phrase or sequence that reads the same backward and forward. For example, madam, radar etc.

Palindrome.java

import java.util.*;
class Palindrome
{
    public static void main(String args[])
    {
       String original, reverse = "";
       Scanner in = new Scanner(System.in);

       System.out.println("Enter a string to check palindrome");
       original = in.nextLine();

       int length = original.length();

       for ( int i = length - 1; i >= 0; i-- )
           reverse += original.charAt(i);

       if (original.equals(reverse))
           System.out.println("Entered string is a palindrome.");
       else
           System.out.println("Entered string is not a palindrome.");
   }
}


Output:

palindrome