42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
import java.util.Random;
|
|
import java.io.*;
|
|
|
|
public class Devinette
|
|
{
|
|
public static void main(String[] args)
|
|
{
|
|
|
|
Random rand = new Random();
|
|
int number =(1+rand.nextInt(100));
|
|
int tentative = 5;
|
|
while(tentative > 0)
|
|
{
|
|
System.out.println("Nombre de tentative : "+tentative);
|
|
--tentative;
|
|
try{
|
|
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
|
|
String player_input = input.readLine().trim();
|
|
int player_try =Integer.parseInt(player_input);
|
|
if(player_try == number)
|
|
{
|
|
System.out.println(player_try+" est le nombre mystere !");
|
|
return;
|
|
}
|
|
else if(player_try < number)
|
|
{
|
|
System.out.println("C'est plus !");
|
|
}
|
|
else
|
|
{
|
|
System.out.println("C'est moins !");
|
|
}
|
|
}catch(IOException e){
|
|
System.err.println(e.getMessage());
|
|
System.exit(1);
|
|
}catch(NumberFormatException e){
|
|
System.out.println("Vous devez choisir un nombre !");
|
|
}
|
|
}
|
|
System.out.println("Perdu ! C'est : "+number);
|
|
}
|
|
} |