Why it's displays error I can't find it. Can you explain me in detail? Why it's happening?
import java.util.*; class stack { public static void Push(int top, int[] stack) { Scanner sc = new Scanner(System.in); if (top == stack.length - 1) { System.out.println("Stack Overflow"); System.exit(1); } else { System.out.println("Pushed element in Stack: "); int n = sc.nextInt(); ++top; stack[top] = n; } sc.close(); } public static void Pop(int top, int[] stack) { if (top == -1) { System.out.println("Stack Empty"); System.exit(1); } else { int item = stack[top]; top--; System.out.println("Deleted item: " + item); } } public static void Disp(int top, int[] stack) { if (top == -1) { System.out.println("Stack Empty"); } else { for (int a : stack) { System.out.println(a); System.out.println(); }