Java game using Random, Boolean, Scanner, while, if / else [closed]

-4

The idea of the game is to use a random from 1 to 100 and the user hits, when the user's number is higher, send a message warning the user, likewise if it is smaller and giving more chances for the user to hit.

The code itself is not compiling and I'm not finding the error

public static void main(String[] args) {

    Random rand = new Random();
    int numeroSorte = rand.nextInt(100) + 1;

    System.out.println("Adivinhe o numero que estou pensando, ele esta entre 1 e 100");

    boolean continuar = true;

    Scanner scan = new Scanner(System.in); 
    while (continuar) {

        System.out.print("digite um numero ");
        int numeroUsuario = Integer.valueOf(scan.next());

        if (numeroUsuario == numeroSorte) {
            System.out.println("Parabens Voce acertou o numero ! ^^ ");
            continuar = false;

        } else if (numeroUsuario < numeroSorte) {
            System.out.println("o numero " + numeroUsuario + "é menor que o meu numero");
        } else {
            System.out.println("o numero " + numeroUsuario + "é maior que o meu numero");
        }
    }
    scan.close();

}
}
    
asked by anonymous 01.07.2018 / 19:25

1 answer

0

It would be a lot easier if I could copy the code, change it and put the corrected version in this answer, but you posted the code as a damn image and so it gets difficult.

The problem is that random rand = newrandom(); should be Random rand = new Random(); . Pay attention to capital letters and space.

You also forgot the import s of Random and Scanner .

You also appear to have placed your class in the wrong folder or with an incorrect package declaration.

Use the break; statement instead of a continuar variable.

scan.close(); is not something that makes sense to do.

    
01.07.2018 / 19:41