as a personnal project to learn Java, i tried to code a priceright game. Unfortunately an issue withe Random function occured, causing a result way outside the range indicated. here is the code: package games;
import java.util.Random;
import java.util.Scanner;
public class priceright{
Scanner priceright = new Scanner(System.in);
int reponse_candidat =priceright.nextInt();
public static void main(String [] args){
System.out.println("veuillez rentrer une valeur: ");
priceright var1 = new priceright();
Random var2 = new Random(200);
if (var1.reponse_candidat < var2.nextInt()) {
System.out.println("c'est plus! la bonne réponse est: " + var2.nextInt());
}else if (var1.reponse_candidat > var2.nextInt()){
System.out.println("c'est moins! la bonne réponse est: " + var2.nextInt());
}else {
System.out.println("vous avez gagné!!!!");
}
}
}
and here is the result i had: veuillez rentrer une valeur: 12 c'est moins! la bonne réponse est: -1090705963
Aucun commentaire:
Enregistrer un commentaire