Utilitaire, exemple variables

This commit is contained in:
Meutel 2019-05-30 08:47:37 +02:00
parent d824ad8009
commit d62d18dd19
3 changed files with 68 additions and 0 deletions

9
Template.java Normal file
View File

@ -0,0 +1,9 @@
import static utils.Utils.*;
public class Template { // FIXME A CHANGER
public static final void main(String[] args) {
afficher("EXEMPLE");
}
}

23
Variables.java Normal file
View File

@ -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);
}
}

36
utils/Utils.java Normal file
View File

@ -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();
}
}
}