Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- * Program to Check whether a given word is a
- * Palindrome or not.
- * @author Steve Robinson
- * @see footyntech.wordpress.com
- */
- class Palindrome
- {
- public static void main(String arg[])
- {
- String word;
- Scanner in=new Scanner(System.in);
- System.out.print("Enter the word: ");
- word=in.next();
- boolean flag=true;
- int j=0;
- for(int i=word.length()-1;i>=0;i--)
- {
- if(Character.toLowerCase(word.charAt(i))!=Character.toLowerCase(word.charAt(j))) {
- flag=false;
- break;
- }
- j++;
- }
- if(flag)
- System.out.println("The given word is a Palindrome!");
- else
- System.out.println("The given word is not a Palindrome!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement