1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class JustePrix
{
private static final BufferedReader lecteurClavier = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException
{
jouerParties();
}
private static void jouerParties() throws IOException
{
boolean continuerDeJouer = true;
while (continuerDeJouer)
{
jouerPartie();
System.out.println("Voulez-vous rejouer (O : Oui, N : Non) ?");
String input = lecteurClavier.readLine();
if ("N".equals(input))
{
continuerDeJouer = false;
}
}
}
private static void jouerPartie() throws IOException
{
int Prix = -1;
int Compteur = 0;
Random rnd = new Random();
int JustePrix = rnd.nextInt(10);
System.out.println("Vous devez deviner le prix, attention... partez !");
while ((Prix < JustePrix) || (Prix > JustePrix))
{
String input = lecteurClavier.readLine();
Prix = Integer.parseInt(input);
Compteur = Compteur + 1;
if (Prix < JustePrix)
System.out.println("C'est +");
if (Prix > JustePrix)
System.out.println("C'est -");
}
System.out.println("Vous avez gagné en " + Compteur + " fois !");
}
} |