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
| public class Exercice2_11 {
public static java.util.Scanner scanner = new java.util.Scanner(System.in);
public static void main(String[] args) {
int premierNombre, secondNombre, reponseEleve, deuxiemeChance, troisiemeChance, reponseCorrecte;
premierNombre = unEntierAuHasardEntre (0, 10);
secondNombre = unEntierAuHasardEntre (0, 10);
System.out.println ("Calculez : ");
System.out.println ( premierNombre * secondNombre + "=" + " ... " );
reponseEleve = scanner.nextInt();
if (reponseEleve = reponseCorrecte )
System.out.println ("Très bien");
else {
System.out.println ("La réponse est fausse!");
System.out.println ("Deuxième chance :");
deuxiemeChance = scanner.nextInt();
if (deuxiemeChance = reponseCorrecte )
System.out.println ("Très bien");
else{
System.out.println ("La réponse est fausse!");
System.out.println ("Vous avez le droit à une dernière chance :");
troisiemeChance = scanner.nextInt();
if (troisiemeChance = reponseCorrecte)
System.out.println ("Très bien");
else
System.out.println ("La réponse est fausse!");
System.out.println ("La réponse correcte était :" + reponseCorrecte);
}
}
}
public static int unEntierAuHasardEntre (int valeurMinimale, int valeurMaximale){
double nombreRéel;
int résultat;
nombreRéel = Math.random();
résultat = (int) (nombreRéel * (valeurMaximale - valeurMinimale + 1))
+ valeurMinimale;
return résultat;
}
} |