Saturday, June 13, 2015

Q.6 - Determine whether a given string is palindrome or not

public class Palindrome{
public static void main(String args[]){
char str[] = args[0].toCharArray();
int strLength = str.length-1;

for(int i=0, j=strLength;i<=strLength/2;i++,j--)
{
if(str[i] != str[j])
{
System.out.println("No");
return;
}
else
continue;
}

System.out.println("Palindrome");

}
}

No comments:

Post a Comment