06-04-2011, 01:20 PM
Code:
import java.io.*;
class Dem20
{
public static void main(String args[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int i,n=0;
String s1;
try
{
System.out.println("enter the size of array:");
n=Integer.parseInt(b.readLine());
String s=new String[n];
System.out.println("enter the string:");
for(i=0;i<n;i++)
{
s[i]=b.readLine();
}
for(i=0;i<n;i++)
{
StringBuffer sb=new StringBuffer(s[i]) ;
s1=new String(sb.reverse());
if(s[i].equals(s1))
{
System.out.println("String is"+s[i]+""+"palindrome");
}
else
{
System.out.println("String is"+s[i]+""+"not palindrome");
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT
E:\3msc\java\meenu>java Dem20
enter the size of array:
3
enter the string:
aba
joby
jiss
String is aba palindrome
String is joby not palindrome
String is jiss snot palindrome