Lab 3: Guessing Game
In this lab you will use selection and repetition structures to create a simple game.
import java.lang.Math;
// import the Math class for random numbers
- Generate a random integer between 1 and 100 using (int) (100*Math.random()) + 1.
- Prompt the user to guess an integer between 1 and 100 inclusive, or 0 to quit.
- Get the user's input from the keyboard.
See ConsoleString.java or
KeyboardString.java.
- Test and inform the user whether his or her guess is too high, too low or correct.
- Keep looping until the user guesses correctly or enters 0.
- If the user enters 0, display the correct answer and quit.
- Compile, run and debug the program.
- Try to answer this mathematics question (and add to the source code in a comment):
What is the maximum number of intelligent guesses needed to correctly guess the number?
- Send the source code to the
instructor as an attachment with subject java lab3.