public class CheckPalindrome{
public static void main(String[] args) {
String str="madam";
Stack s= new Stack();
int i,count=0;
char array[]=str.toCharArray();
for(i=0;i(less than symbol)array.length;i++)
{
char arr=array[i];
s.push(arr);
}
for(i=0;i(less than symbol)array.length/2;i++)
{
char st=array[i];
Object ob=s.pop( );
if(st==ob) {
count++;
}
}
if(count==array.length/2) {
System.out.println("String is Palindrome");
}
else{
System.out.println("String is not a Palindrome");
}
}
} Labels: Java
Responses
0 Respones to "Palindrome String"
Post a Comment