From 03965cc6b87f9dc601f1fd14e33b519cd78caeac Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 5 Apr 2018 15:38:55 +0200 Subject: [PATCH] exo3: use Scanner class in more places. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exo3/Main.java | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/exo3/Main.java b/exo3/Main.java index e92a5e2..33f6bbc 100644 --- a/exo3/Main.java +++ b/exo3/Main.java @@ -41,11 +41,20 @@ class Main { } private static void main_A(String[] args) { - if (args.length == 0) { - System.out.println("Please run with java Main "); - System.exit(-1); + String className = null; + Scanner uInput = null; + try { + uInput = new Scanner(System.in); + System.out.println("Saisir le nom de la classe à inspecter:"); + className = uInput.nextLine(); + } + catch (Exception e) { + System.out.println("Erreur:"); + e.printStackTrace(); + } + finally { + uInput.close(); } - String className = args[0]; Class cl = null; try { @@ -68,11 +77,7 @@ class Main { } } - /** - * The main() function - * @param String[] args main() function arguments array - */ - public static void main(String[] args) { + private static void main_B(String[] args) { String name = Entiers.class.getName(); Class cl = null; Entiers o = null; @@ -89,7 +94,7 @@ class Main { try { uInput = new Scanner(System.in); System.out.println("Saisir le nom de la methode à invoquer:"); - String method = uInput.next(); + String method = uInput.nextLine(); //TODO: one can build the input list from the method arguments list and types System.out.println("Saisir l'argument entier paramètre de la méthode:"); int integer = uInput.nextInt(); @@ -117,4 +122,12 @@ class Main { uInput.close(); } } + + /** + * The main() function + * @param String[] args main() function arguments array + */ + public static void main(String[] args) { + main_A(args); + } } -- 2.34.1