July 05, 2013

Java program to check palindrome

C palindrome program, Java Program To Check Palindrome, C++ Program to check for palindrome, program to check palindrome in java, program to check palindrome in c#, program to check palindrome in python

Write an Java Program to check weather given string is palindrome



PALINDROME

import java.io.*;

class palindrome
{
  public static void main(String args[])throws IOException
    {
       BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
       System.out.println("Enter the String ");
      String str=st.readLine();
       String s="";
      for(int i=(str.length())-1;i>=0;i--)
          s=s+str.charAt(i);
       if(s.equals(str))
           System.out.println(str+" is Palindrome ");
       else
           System.out.println(str+" is not a Palindrome");
    }
}





OUTPUT


C:\Program Files\Java\jdk1.5.0\bin>java palindrome
Enter the String
dad
dad is Palindrome

C:\Program Files\Java\jdk1.5.0\bin>java palindrome
Enter the String
tatya

tatya is not a Palindrome

No comments:
Write comments