Page 619 - Computer science 868 Class 12
P. 619
25 break;
26 case 2:
27 int t=ob.popitem();
28 if(t==-9999)
29 {
30 System.out.println("ERROR: Stack underflow");
31 }
32 else
33 {
34 System.out.println("Element"+t+"is Popped from the Stack");
35 }
36 break;
37 case 3:
38 ob.printstack();
39 break;
40 default:
41 System.out.println("Invalid choice");
42 }
43 System.out.println("Do you want to continue?(y/n)");
44 x = sc.next();
45 }
46 while(x.equalsIgnoreCase("y")==true);
47 System.out.println("Thank You");
48 }
49 }
Output of the preceding program is as follows:
Stack Size: 2
Main Menu
Press 1 to Push Item To Stack
Press 2 to Pop Item Out of Stack
Press 3 to Display Items of Stack
Enter Choice: 1
Enter A Number to Push: 99
Do you want to Continue?(y/n)
617
Internal Assessment 617

