Guess the Number

Report a typo

Complete the following program that plays the "Guess the Number" game with a user. It is designed to prompt the user to guess a predefined number. The user will continue to be prompted until the correct number is guessed.

Fill in the gaps with the relevant elements
import java.util.Scanner;

public class NumberGuessingGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int number = 42;
        int userGuess;

        System.out.println("Welcome to the Number Guessing Game!");

         {
            System.out.print("Enter your guess: ");
            userGuess = scanner.nextInt();

            if () {
                System.out.println("Too low! Try again.");
            } else if () {
                System.out.println("Too high! Try again.");
            }

        } ;

        System.out.println("Congratulations! You guessed the correct number: " + number);
    }
}
while (userGuess != number)userGuess < numberuserGuess > numberdo

Create a free account to access the full topic