From f695f9600dc81ed431bafba7fb90386e6c69d411 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 3 Apr 2018 11:57:12 +0200 Subject: [PATCH] exo1: Add the ArrayDeque test code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exo1/Main.java | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/exo1/Main.java b/exo1/Main.java index 5efe910..343504b 100644 --- a/exo1/Main.java +++ b/exo1/Main.java @@ -1,3 +1,5 @@ +import java.util.ArrayDeque; +import java.util.NoSuchElementException; class Main { @@ -65,19 +67,24 @@ class Main { 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(); + } } } -- 2.34.1