Exercise: Number Guessing

Write a console program that picks a random number. The program lets the user guess which number it picked. If the user guessed incorrectly, the program tells the user whether their guessed number is too small or too big.

The program continues until the user guesses the right number.

For example (user input in green):

Please enter a number between 0 and 10
4
Your guessed number is too small
Please enter a number between 0 and 10
6
Your guessed number is too big
Please enter a number between 0 and 10
5
Congratulations, the number is indeed 5

Hint 💡

You can generate a random number between two numbers (inclusive) using the following code snippet:
Random random = new Random();
int lowerInclusive = 0;
int upperInclusive = 10;
int randomInt = random.nextInt(lowerInclusive, upperInclusive + 1);

Hand in instructions

  1. Make sure your program runs correctly.
  2. Hand in your program by uploading Main.java to Moodle.