content: import java.util.Scanner;  
  class Stack   
  {  
      int top;   
      int maxsize = 10;  
      int[] arr = new int[maxsize];  
        
        
      boolean isEmpty()  
      { 
          // If top is negative then stack is empty because  stack was intialized with top=-1 
          return (top < 0);  
      }  
      Stack()  
      {  
          top = -1;  
      }  
      boolean push (Scanner sc)  
      {  
          if(top == maxsize-1)  
          {  
              // if top element index becomes equal to size of array -1 then it becomes overflow
              System.out.println("Overflow !!");  
              return false;  
          }  
          else   
          {  
              System.out.println("Enter Value");  
              int v = sc.nextInt();  
              top++;  
              arr[top]=v;  
              System.out.println("Item pushed");  
              return true;  
          }  
      }  
      boolean pop ()  
      {  
          if (top == -1)  
          {  
              // If top=-1 that means no element is present in the array 
              System.out.println("Underflow !!");  
              return false;  
          }  
          else   
          {  
              top --;   
              System.out.println("Element popped");  
              return true;  
          }  
      }  
      void display ()  
      {  
          System.out.println("Printing stack elements .....");  
          // Iterating over the array from top element to 0 index element because it is stack 
          for(int i = top; i>=0;i--)  
          {  
              System.out.println(arr[i]);  
          }  
      }  
  }  
  public class Stack_Operations {  
  public static void main(String[] args) {  
      int ch=0;  
      Scanner sc = new Scanner(System.in);  
      Stack s = new Stack();  
      System.out.println("*********Stack using array*********\n");  
      while(ch != 4)  
      {  
          System.out.println("\nChose one from the below options...\n");  
          System.out.println("\n1.Push\n2.Pop\n3.Show\n4.Exit");  
          System.out.println("\n Enter your choice \n");        
          ch = sc.nextInt();  
          switch(ch)  
          {  
              case 1:  
              {   
                  s.push(sc);  
                  break;  
              }  
              case 2:  
              {  
                  s.pop();  
                  break;  
              }  
              case 3:  
              {  
                  s.display();  
                  break;  
              }  
              case 4:   
              {  
                  System.out.println("Exiting....");  
                  System.exit(0);  
                  break;   
              }  
              default:  
              {  
                  System.out.println("Please Enter valid choice ");  
              }   
          };  
      }  
  }  
  }  