Write a Java program that checks whether a given string is a palindrome or not. - C C++ Java Programs - Examples

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, October 10, 2011

Write a Java program that checks whether a given string is a palindrome or not.


Write a Java program that checks whether a given string is a palindrome or not.
class Palindrome
{
public static void main(String args[])
{
String s=args[0];
int len,i=0,n,c=0,p;
len=s.length();
n=len/2;
p=len-n+1;
while(i<len/2)
{


if(s.charAt [i]==s.charAt(p))
c++;
i++;
p--;
}
if(c==len/2)
{
System.out.println("palindrom");
}
else
{
System.out.println("not palindrom");
}
}
}

No comments:

Post a Comment