// Program 40: Stack import java.util.*; class StackArray { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] st = new int[5]; int top = -1, choice, item; do { System.out.println("1.Push 2.Pop 3.Display 4.Exit"); choice = sc.nextInt(); if (choice == 1) { if (top == 4) { System.out.println("Stack Overflow"); } else { System.out.print("Item: "); item = sc.nextInt(); st[++top] = item; } } else if (choice == 2) { if (top == -1) { System.out.println("Stack Underflow"); } else { System.out.println("Deleted element: " + st[top--]); } } else if (choice == 3) { if (top == -1) { System.out.println("Stack Underflow"); } else { for (int i = top; i >= 0; i--) System.out.println(st[i]); } } } while (choice != 4); } }