public class Main{ public static void main(String args[]){ Stack s = new Stack(5); for (int i=0;i<10;i++){ try{ s.push(new Integer(i)); } catch (Exception e) { System.out.println("OVERFLOW!"); break; } } for (int i=0;i<10;i++){ try{ System.out.println(s.pop()); } catch (Exception e) { System.out.println("UNDERFLOW!"); break; } } } }