首先,您对keyboard.nextInt()的调用(及其对应的println为“猜测0-100之间的数字”)应该在while循环内。
然后,您应该考虑将while循环更改为
while (true) { // read input from user if (guess < value) { // tell user their guess is too low } else if (guess > value) { // tell user their guess is too high } else { // tell user congrats, and call break to exit the while loop } }}一旦做对了,就可以进行精妙的处理,例如检查猜中的数字是否在范围之内,跟踪他们进行了多少次猜测等。



