Week 3 :
a) 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
{
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