Advertisement
steverobinson

Palindrome|JAVA

Aug 5th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*
  4. *   Program to Check whether a given word is a
  5. *   Palindrome or not.
  6. *   @author Steve Robinson
  7. *   @see footyntech.wordpress.com
  8. */
  9.  
  10. class Palindrome
  11. {
  12.     public static void main(String arg[])
  13.     {
  14.         String word;
  15.         Scanner in=new Scanner(System.in);
  16.         System.out.print("Enter the word: ");
  17.         word=in.next();
  18.         boolean flag=true;
  19.         int j=0;
  20.         for(int i=word.length()-1;i>=0;i--)
  21.         {
  22.             if(Character.toLowerCase(word.charAt(i))!=Character.toLowerCase(word.charAt(j))) {
  23.                 flag=false;
  24.                 break;
  25.             }
  26.             j++;
  27.         }
  28.         if(flag)
  29.             System.out.println("The given word is a Palindrome!");
  30.         else
  31.             System.out.println("The given word is not a Palindrome!");
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement