Monday, November 21, 2011

Write A Program In Java To Find Whether The String Is Palindrome Or Not?

import java .io.*;
class palindrome
{
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String s1,s2=" ";
int i,l;
char ch;
System.out.println("ENTER STRING TO CHECK");
s1=in.readLine();
l=s1.length();
for(i=0;i<l;i++)
{
ch=s1.charAt(i);
s2=ch+s2;
}
if(s1.equals(s2))
System.out.println("PALINDROME");

else
System.out.println("nOT PALINDROME");
}
}

No comments:

Post a Comment

Thank you for your comment