Sunday, January 1, 2012

Palindrome Code


import java.util.*;
class palin12
{
public static void main(String args[])
{
String s1;
String s2="";
System.out.println("Enter the String");
Scanner scan=new Scanner(System.in);
s1=scan.next();

int l=s1.length();
char c[]=new char[l];
for(int i=l-1;i>=0;i--)
{
c[i]=s1.charAt(i);
s2=s2+c[i];
}
System.out.println(s2);
if(s1.equals(s2))
{
System.out.println("palindrome");
}
else
{
System.out.println("not palindrome");
}
}
}

output:
Enter the String

malayalam
malayalam
palindrome


Enter the String
bharath
htarahb
not palindrome




1 comment:

  1. Hi da machi. suber da.u did the good job. its realy usefull for me. keep it good one.

    -venkat.

    ReplyDelete