From d62d18dd19aa2e36378784305b85994a9a2b04f9 Mon Sep 17 00:00:00 2001 From: Meutel Date: Thu, 30 May 2019 08:47:37 +0200 Subject: [PATCH] Utilitaire, exemple variables --- Template.java | 9 +++++++++ Variables.java | 23 +++++++++++++++++++++++ utils/Utils.java | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 Template.java create mode 100644 Variables.java create mode 100644 utils/Utils.java diff --git a/Template.java b/Template.java new file mode 100644 index 0000000..1cbf1b8 --- /dev/null +++ b/Template.java @@ -0,0 +1,9 @@ +import static utils.Utils.*; + +public class Template { // FIXME A CHANGER + + public static final void main(String[] args) { + afficher("EXEMPLE"); + } + +} diff --git a/Variables.java b/Variables.java new file mode 100644 index 0000000..09ddecc --- /dev/null +++ b/Variables.java @@ -0,0 +1,23 @@ +import static utils.Utils.*; + +public class Variables { + + public static final void main(String[] args) { + int a = 0; + + char b; + b = '0'; + + boolean c = true; + boolean d = false; + + afficher(a, b, c, d); + afficher("c ou d"); + afficher(c || d); + + boolean expr1 = c && d; + afficher(expr1); + + } + +} diff --git a/utils/Utils.java b/utils/Utils.java new file mode 100644 index 0000000..8626d5c --- /dev/null +++ b/utils/Utils.java @@ -0,0 +1,36 @@ +package utils; + +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.Scanner; + + +public class Utils { + + public static final void afficher(Object... args) { + if (args == null) { + System.out.println("null"); + } else { + String str = Arrays.stream(args) + .map(String::valueOf) + .collect(Collectors.joining(" ")); + System.out.println(str); + } + System.out.println(); + } + + public static int lireEntier() { + try (Scanner reader = new Scanner(System.in)) { + System.out.println("Saisir un entier: "); + return reader.nextInt(); + } + } + + public static String lireChaine() { + try (Scanner reader = new Scanner(System.in)) { + System.out.println("Saisir une valeur et valider: "); + return reader.nextLine(); + } + } + +}