From: Jérôme Benoit Date: Tue, 3 Apr 2018 09:57:12 +0000 (+0200) Subject: exo1: Add the ArrayDeque test code. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f695f9600dc81ed431bafba7fb90386e6c69d411;p=Project_POO.git exo1: Add the ArrayDeque test code. Signed-off-by: Jérôme Benoit --- 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(); + } } }