ITEC 120 LAB 17 Back to Lab index page

Guessing game

Write a java program (again, can be done in one file, with one main method) which allows the user to guess a number between 1 and 25. If they guess incorrectly, the program will tell them if they should guess higher or lower. Allow the user to guess until they get the number right. Report to the user the number of guesses it took them to get the number. Your program should then ask the user if they'd like to play again.

NOTE : Use the Scanner method .next() to read the user's answer to "Want to play again?" to avoid a problem you will experience if you use .nextLine(). .next()returns a String.

Sample 1

Program displays: Guess a number between 1 and 15:
User enters: 12
Program displays: No, guess higher.
User enters: 18
Program displays: No, guess lower.
User enters: 16
Program displays: No, guess higher.
User enters: 17
Program displays:

That's it! You got the number in 4 guesses!

Want to play again? (yes or no)

User enters: no