import javax.swing.JOptionPane;
class PalindromeString
{
private char[]stack;
private int top;
public PalindromeString(int cap)
{
stack=new char[cap];
top=-1;
}
public void push(char element)
{
stack[++top]=element;
}
public char pop()
{
return stack[top--];
}
public boolean isEmpty()
{
return top<0;
}
public boolean isFull()
{
return top==stack.length-1;
}
}
class palindromestringtest
{ public static void main(String []args)
{
String s=JOptionPane.showInputDialog(null,"Enter a String:");
String rev="";
PalindromeString p=new PalindromeString(s.length());
for(int i=0;i
{
p.push(s.charAt(i));
}
while(!p.isEmpty())
{
rev+=p.pop();
}
if(rev.equals(s))
JOptionPane.showMessageDialog(null,"String \""+s+"\" is palindrome.");
else
JOptionPane.showMessageDialog(null,"String \""+s+"\" is not palindrome.");
}
}
Read More ->>