Skip to content

Commit aa5f4e1

Browse files
committed
Implements the Stack class
1 parent d44645b commit aa5f4e1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

general/StackDemo.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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("\nEnter your choice : ");
14+
15+
switch(in.nextInt()){ // Accepts incase of integer input.
16+
case 1:
17+
System.out.println("\nEnter 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+
}

0 commit comments

Comments
 (0)