User after speculation, update tip number range, and the program should limit the user to guess the number, by making
The user to select difficulty confirmation number limit, simple difficulty 10 times, normal difficulty eight times, difficult difficult 5 times,
Hell difficulty 3 times,
Procedures shall strictly comply with the following example, the green font for user input
* * * * * * * * guess Numbers game * * * * * * * *
You can within a limited opportunity to a 0-100 scale digital kitchen knife?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
(please select a difficulty (simple [S] [N]/[D]/[H]) hell difficulty: S
Simple is difficult, you have 10 times opportunity
The first guess: the number between 0-100: 50
Guess wrong! The number is less than 50
The second guess, the number between 0 and 49: and
Guess wrong! The number is less than 26
Guess for the third time, the number between 0 and 25: 13
Guess wrong! The number is less than 13
Fourth is forecasted, the number between 0-12: 13
Invalid input! Please enter a number between 0 and 12
Fourth is forecasted, the number between 0-12: 6
Guess wrong! The number is greater than 6
Fifth is forecasted, the number between 7-12: 5
Invalid input! Please enter a number between 7 to 12
Fifth is forecasted, the number between 7-12: 10
Guess wrong! The number is less than 10
Sixth is forecasted, the number between 7-9:
Guess wrong! The number is greater than 8
Guess, for the seventh time the number between 9-9: 9
Congratulations to you! After seven times try, finally guessed right!
* * * * * * * * guess Numbers game * * * * * * * *
You can within a limited opportunity to a 0-100 scale digital kitchen knife?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
(please select a difficulty (simple [S] [N]/[D]/[H]) hell difficulty: H
Hell difficulty, you have three chances to
Guess the first time, the number between 0-100: 80
Guess wrong! The number is less than 80
The second guess, the number between 0-79: 60
Guess wrong! The number is greater than 60
Guess for the third time, the number between 61-79: 66
Guess wrong! The number is larger than 66
Very sorry! Your chance to run out!
CodePudding user response:
If statement simply, middle limit again, guess the number offor(int i=0; i<(number of different levels of speculation); I++) {
If (you guessed number==randomly generated Numbers) {
System. Out.println (" right ")
Return you guess the number
} else {
System. Out.println (" wrong ")
}
}
The basic logic is like this