How to build a simple game in java that will allow a player to attempt to guess a randomly generated number between 0 and 10. The player can continue guessing the number until they get it right.

The game should be able to do these things:
1. Game should remember each choice that the player enters.
2. Each time the player gets the guess wrong you should tell the to try again.
3. If the player guesses correctly tell them so.
4. The game should then print out all the values that the player entered, in the order in which they were entered.
5. Once they’ve guessed the correct number and seen their list of guesses, they can play again, but only five (5) times.

1 answer

import java.util.Scanner;
public class GuessNumberUsingBreak {
public static void main(String[] args) {
int number = (int)(Math.random() * 101);
System.out.println(number);
Scanner input = new Scanner(System.in);
while (true) {
// Prompt the user to guess the number
System.out.print("Guess a number between 0 ad 100.\nEnter your guess: ");
int guess = input.nextInt();

if (guess == number) {
System.out.println("Congratulations! " +
"You have chosen the correct number! \nThe correct number is " + number);
break;
}
else if (guess > number) {
System.out.println("Your guess is too high");
}
else {
System.out.println("Your guess is too low");
}
}
}
}