Go to Top

Friday, 14 October 2011

Check Palindrome String

Question 61 : Write a program in Java to check whether a String is Palindrome or not.

Java Program :

import java.io.*;
class palindrome
{
     String s,s1;
      palindrome()
     {
         s="";
         s1="";
        }
        void Palin()throws IOException
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter the word : ");
            s=br.readLine();
            for(int i=s.length()-1;i>=0;i--)
            s1=s1+s.charAt(i);
            if(s1.equals(s))
            System.out.print("\nThe word '"+s+"' is palindrome");
            else
            System.out.print("\nThe word '"+s+"' is not palindrome");
        }
    }
     

1 comment:

ShareThis