Stack Program

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);
}
}

All Rights Reserved The Origin for Screamers | Design by SCREAMERS
Computers
Top Blogs