5 Juin
This commit is contained in:
parent
4c2939df42
commit
b2e4a82bd9
BIN
DEV2.1/TP12:FluxDeCaracteres/Devinette.class
Normal file
BIN
DEV2.1/TP12:FluxDeCaracteres/Devinette.class
Normal file
Binary file not shown.
38
DEV2.1/TP12:FluxDeCaracteres/Devinette.java
Normal file
38
DEV2.1/TP12:FluxDeCaracteres/Devinette.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user