Wednesday, 8 February 2017

Java Program to check If a String is Palindrome or not

A palindrome String is a word, phrase, number, or others sequence of characters which reads the same backward or forward, such as madam or kayak. " Here is the java program to check if a String is palindrome or not.


import java.util.Scanner;

public class palindrome{
      
       public static void main(String args[])
       {
            Scanner in=new Scanner(System.in);
            String original=in.next();
            String reverse="";
            int i;
            for(i=original.length()-1;i>=0;i--)
            {
                  reverse=reverse+original.charAt(i);
            }
            System.out.print("\n");
            System.out.print("The orignal string is: "+original);
            System.out.print("\n\n");
            System.out.print("The reverse String is: "+reverse);
            System.out.print("\n");
            if(original.equals(reverse))
            {
                 System.out.print("\nString is palindrome");
            }
            else
            {
                 System.out.print("\nString is not palindrome");
            }
       }
}

  Output: 




EmoticonEmoticon