PROGRAM TO CHECK WHETHER A WORD IS PALINDROME OR NOT






PROGRAM TO CHECK WHETHER THE GIVEN WORD IS PALINDROME OR ONLY A SPECIAL WORD USING INPUT BY THE USER.
WHAT IS A PALINDROME WORD?
Palindrome words are those words which read the same from left to right and vice-versa. 
eg,. MADAM, ROTATOR, MALAYALAM etc.
whereas a special words are those words which start and ends with the same letter. 
eg,. EXISTENCE, COMIC, WINDOW etc.


The following program demonstrates the above explained points:
import java.util.*;
class p
{
    public static void main(String args[])
    {
        Scanner ob = new Scanner (System.in);
        System.out.println("enter a word");
        String s = ob.next();
        String rev = "";
        for(int i= s.length()-1; i >= 0; i--)
        {
            char ch = s.charAt(i);
            rev = rev +ch;
        }
        if(s.equalsIgnoreCase(rev))
        {
            System.out.println(s+ " is a Palindrome word");
        }
        else if (s.charAt(0) == s.charAt(s.length()-1))
        {
            System.out.println(s+"is only a special word");
        }
    }
}

THANK YOU!!

Comments

Popular Posts