File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+ class StackDemo {
3
+ public static void main (String [] args ){
4
+ Stack st = new Stack ();
5
+ int data , choice ;
6
+
7
+ while (true ){
8
+ Scanner in = new Scanner (System .in );c // Takes input from user.
9
+ System .out .println ("1. Push Element" );
10
+ System .out .println ("2. Pop Element" );
11
+ System .out .println ("3. Display Element" );
12
+ System .out .println ("4. Exit Program" );
13
+ System .out .print ("\n Enter your choice : " );
14
+
15
+ switch (in .nextInt ()){ // Accepts incase of integer input.
16
+ case 1 :
17
+ System .out .println ("\n Enter value : " );
18
+ data = in .nextInt (); // Receives input from user.
19
+ st .push (data );
20
+ break ;
21
+ case 2 :
22
+ st .pop ();
23
+ break ;
24
+ case 3 :
25
+ st .display ();
26
+ break ;
27
+ case 4 :
28
+ System .exit (0 ); // Halts the program.
29
+ }
30
+
31
+ }
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments