From 77ee242b4fa823fb75b515b1362351d387b3437a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Wed, 1 Dec 2021 16:54:11 +0100 Subject: [PATCH] --- .../C081_Enum/App.java | 1 + src/various_tests/Input.java | 84 +++++++++++++++++++ src/various_tests/L02tests.java | 12 +++ src/various_tests/bug_encodage.java | 19 +++++ 4 files changed, 116 insertions(+) create mode 100644 src/various_tests/Input.java create mode 100644 src/various_tests/L02tests.java create mode 100644 src/various_tests/bug_encodage.java diff --git a/src/C08_Structures_de_donnees/C081_Enum/App.java b/src/C08_Structures_de_donnees/C081_Enum/App.java index d5b06ec..0437149 100644 --- a/src/C08_Structures_de_donnees/C081_Enum/App.java +++ b/src/C08_Structures_de_donnees/C081_Enum/App.java @@ -25,6 +25,7 @@ public class App { case FRAISE: System.out.println("Fraise"); favorite = Glace.MANGUE; + break; default: System.out.println("Mangue"); diff --git a/src/various_tests/Input.java b/src/various_tests/Input.java new file mode 100644 index 0000000..112d01a --- /dev/null +++ b/src/various_tests/Input.java @@ -0,0 +1,84 @@ +package various_tests; +import java.io.*; +import java.nio.charset.StandardCharsets; +//import java.nio.charset.spi.CharsetProvider; +//import java.util.Scanner; +//import java.nio.charset.Charset; + +/** +* The Class Input is here to enter data with the keyboard.
+* The types below are supported by the Input class.

+* - String
- Integer (int)
- Double (double) - Boolean (boolean)
- Character (char)


+* @see #readString() +* @see #readInt() +* @see #readDouble() +* @see #readBoolean() +* @see #readChar() +*/ +public class Input +{ + /** + * Reads a String from the console. + * @return The typed string + * @see java.lang.String + */ + public static String readString() + { + // VERSION PROF + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_16)); + try {return stdin.readLine(); } + catch (Exception ex) { return "";} + + /* // VERSION PERSO + Scanner scanner = new Scanner(System.in); + return scanner.nextLine(); + */ + } + + /** + * Reads an Integer from the console. + * @return The typed Integer or 0 if the typed Integer is invalid + * @see java.lang.Integer + */ + public static int readInt() + { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + try { return Integer.parseInt(stdin.readLine()); } + catch (Exception ex) { return 0; } + } + + /** + * Reads a Double from the console. + * @return The typed Double or 0 if the typed Double is invalid + * @see java.lang.Double + */ + public static double readDouble() + { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + try { return Double.parseDouble(stdin.readLine()); } + catch (Exception ex) { return 0; } + } + + /** + * Reads a boolean from the console. + * @return The typed boolean or false if the typed boolean is other than "true" + */ + public static boolean readBoolean() + { + + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); } + catch (Exception ex) {return false; } + } + + /** + * Reads a char from the console. + * @return The typed char or the character 0 if the typed char is invalid + */ + public static char readChar() + { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + try { return stdin.readLine().charAt(0); } + catch (Exception ex) {return '\0'; } + } +} \ No newline at end of file diff --git a/src/various_tests/L02tests.java b/src/various_tests/L02tests.java new file mode 100644 index 0000000..177b808 --- /dev/null +++ b/src/various_tests/L02tests.java @@ -0,0 +1,12 @@ +package various_tests; + +public class L02tests { + + public static void main(String[] args) { + int x = 10; + x ^= 3; + + System.out.println(x); + } + +} diff --git a/src/various_tests/bug_encodage.java b/src/various_tests/bug_encodage.java new file mode 100644 index 0000000..d6fa0bf --- /dev/null +++ b/src/various_tests/bug_encodage.java @@ -0,0 +1,19 @@ +package various_tests; + +import hevs.utils.Input; + +public class bug_encodage { + + public static void main(String[] args) { + String s = "héllo"; + System.out.println(s); + s = ""; + while (true) { + s = Input.readString(); + System.out.println(s); + } + } + +} + +//commentaire pour l'exemple \ No newline at end of file