DEV/DEV2.1/TP12:FluxDeCaracteres/Devinette.java

38 lines
977 B
Java
Raw Permalink Normal View History

2023-06-05 11:30:54 +02:00
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);
}
}