diff --git a/DEV2.1/TP12:FluxDeCaracteres/Devinette.class b/DEV2.1/TP12:FluxDeCaracteres/Devinette.class new file mode 100644 index 0000000..eb42138 Binary files /dev/null and b/DEV2.1/TP12:FluxDeCaracteres/Devinette.class differ diff --git a/DEV2.1/TP12:FluxDeCaracteres/Devinette.java b/DEV2.1/TP12:FluxDeCaracteres/Devinette.java new file mode 100644 index 0000000..a53904a --- /dev/null +++ b/DEV2.1/TP12:FluxDeCaracteres/Devinette.java @@ -0,0 +1,38 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; +import java.util.*; +import java.io.*; + +public class Devinette{ + + public static void main(String[] args) { + Random rand = new Random(); + int aleatoire = (rand.nextInt()%100); + if(aleatoire < 0){ + aleatoire = -aleatoire; + } + int n=0; + String lec=""; + InputStreamReader itr = new InputStreamReader(System.in); + BufferedReader bfr = new BufferedReader(itr); + for(int i=0;i<5;i++){ + try{ + lec = bfr.readLine().trim(); + }catch(IOException e){ + System.out.println("Erreur de lecture"); + }try{ + n = Integer.parseInt(lec); + }catch(NumberFormatException e){ + System.out.println("Vous devez choisir un nombre"); + } if (n == aleatoire){ + System.out.println("Vous avez gagner!"); + break; + }else if(n < aleatoire){ + System.out.println("Plus grand!"); + }else{ + System.out.println("Plus petit!"); + } + } System.out.println("Le nombre secret etait: "+aleatoire); + } +} \ No newline at end of file