mercredi 7 août 2019

Reverse Guessing Game for java

I've been trying to create a reverse guessing game wherein the user will input a number and then the program/bot will try to guess what number the user gave. I have a problem with random generator in the program. For example, when the user inputs a number such as 157, the bot will generate a number. If the number that bot gave is lower than 157, the user will then click the higher button (lower button if the number is higher). My problem is it doesn't generate properly and just give a random number.

I've tried changing the formula for Math.random() but I still can't figure it out.

Here's my code for the jbutton (higher) in netbeans :

if(con > con2) {
    int generator = (int)(Math.random() * (1 + high - low))+low;
    String conv = Integer.toString(generator);
    jTextField2.setText(conv);
}




Aucun commentaire:

Enregistrer un commentaire