Tuesday, October 9, 2012

Java Exercise #17: Guess Number

This program is for the user to guess the number computer has randomly generated

Exercise: Write a program that randomly generates an integer between 0 and 100 (inclusive). The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each input, the program tells the user whether the input is too high or too low, so that user can make intelligent guess. Following is a sample run.

Guess a number between 0 and 100
Enter your guess: 50
The number is too low
Enter your guess: 75
The number is too high
Enter your guess: 63
The number is too low
Enter your guess: 70
The number is too high
Enter your guess: 67
The number is too high
Enter your guess: 65
The number is too low
Enter your guess: 66
Yes, the number is 66

Download Code: Guess Number

No comments:

Post a Comment