exo1: Add the ArrayDeque test code.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 3 Apr 2018 09:57:12 +0000 (11:57 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 3 Apr 2018 09:57:12 +0000 (11:57 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
exo1/Main.java

index 5efe9108b31922637b11e0a2c33f414be4facae2..343504b9d22c6edcd31a0be30916b48a0bb9ab2d 100644 (file)
@@ -1,3 +1,5 @@
+import java.util.ArrayDeque;
+import java.util.NoSuchElementException;
 
 class Main {
 
 
 class Main {
 
@@ -65,19 +67,24 @@ class Main {
         stackStrDeq.push("Hi");
         stackStrDeq.push("Hugh");
 
         stackStrDeq.push("Hi");
         stackStrDeq.push("Hugh");
 
-        System.out.println("Stack index " + stackStrDeq.size());
-        System.out.println("Stack head value " + stackStrDeq.pop());
-        System.out.println("Stack index " + stackStrDeq.size());
-        System.out.println("Stack head value " + stackStrDeq.pop());
-        System.out.println("Stack index " + stackStrDeq.size());
-        System.out.println("Stack head value " + stackStrDeq.pop());
-        System.out.println("Stack index " + stackStrDeq.size());
-        System.out.println("Stack head value " + stackStrDeq.pop());
-        System.out.println("Stack index " + stackStrDeq.size());
-        System.out.println("Stack head value " + stackStrDeq.pop());
-        System.out.println("Stack index " + stackStrDeq.size());
-        System.out.println("Stack head value " + stackStrDeq.pop());
-        System.out.println("Stack index " + stackStrDeq.size());
-
+        try {
+            System.out.println("Stack index " + stackStrDeq.size());
+            System.out.println("Stack head value " + stackStrDeq.pop());
+            System.out.println("Stack index " + stackStrDeq.size());
+            System.out.println("Stack head value " + stackStrDeq.pop());
+            System.out.println("Stack index " + stackStrDeq.size());
+            System.out.println("Stack head value " + stackStrDeq.pop());
+            System.out.println("Stack index " + stackStrDeq.size());
+            System.out.println("Stack head value " + stackStrDeq.pop());
+            System.out.println("Stack index " + stackStrDeq.size());
+            System.out.println("Stack head value " + stackStrDeq.pop());
+            System.out.println("Stack index " + stackStrDeq.size());
+            // It will trigger the exception
+            System.out.println("Stack head value " + stackStrDeq.pop());
+            System.out.println("Stack index " + stackStrDeq.size());
+        }
+        catch (NoSuchElementException e) {
+            e.printStackTrace();
+        }
     }
 }
     }
 }