Stack Program
Do you like this story?
import java.util.*;
import javax.swing.JOptionPane;
class Stackdemo
{
public static void main(String[] args)
{
Stack st=new Stack();
int j;
do
{
String s=JOptionPane.showInputDialog("enter ur choice\n1->input\n2->delete\n3->exit");
j=Integer.parseInt(s);
if(j==1)
{
s=JOptionPane.showInputDialog("enter an element");
st.push(Integer.parseInt(s));
JOptionPane.showMessageDialog(null,"stack elements:"+st,"stack elements",JOptionPane.INFORMATION_MESSAGE);
}
try
{
if(j==2)
{
Integer a=(Integer)st.pop();
JOptionPane.showMessageDialog(null,"stack elements:"+st,"stack elements",JOptionPane.INFORMATION_MESSAGE);
}
}
catch(EmptyStackException e)
{
JOptionPane.showMessageDialog(null,"STACK IS EMPTY"+e,"stack elements",JOptionPane.INFORMATION_MESSAGE);
}
}while(j<3);
}
}
import javax.swing.JOptionPane;
class Stackdemo
{
public static void main(String[] args)
{
Stack st=new Stack();
int j;
do
{
String s=JOptionPane.showInputDialog("enter ur choice\n1->input\n2->delete\n3->exit");
j=Integer.parseInt(s);
if(j==1)
{
s=JOptionPane.showInputDialog("enter an element");
st.push(Integer.parseInt(s));
JOptionPane.showMessageDialog(null,"stack elements:"+st,"stack elements",JOptionPane.INFORMATION_MESSAGE);
}
try
{
if(j==2)
{
Integer a=(Integer)st.pop();
JOptionPane.showMessageDialog(null,"stack elements:"+st,"stack elements",JOptionPane.INFORMATION_MESSAGE);
}
}
catch(EmptyStackException e)
{
JOptionPane.showMessageDialog(null,"STACK IS EMPTY"+e,"stack elements",JOptionPane.INFORMATION_MESSAGE);
}
}while(j<3);
}
}

This post was written by: Rajendra Prasad
Rajendra Prasad is a professional blogger, web designer and front end web developer. Follow him on Facebook