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.
While and do-while loops
Guess the Number
Report a typo
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);
}
}Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.