This commit is contained in:
Adrian POURCHOT 2023-06-05 11:30:54 +02:00
parent 4c2939df42
commit b2e4a82bd9
2 changed files with 38 additions and 0 deletions

Binary file not shown.

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