public static void main(String[] args) throws IOException {
System.out.println("Hello, come and play a game with me!");
int x = 5;
int guess;
do {
System.out.println("Please input a number...");
guess = System.in.read();
guess = System.in.read();
if (guess < 5) {
System.out.println("You guessed the number!");
break;
}
} while (guess > 5);
}
所以这里我写了一些代码。它应该是一个猜谜游戏,但无论我输入什么内容,它总是会在输出中输入“请输入一个数字......”不管我放哪个。基本上,如果“猜测”超过5,那么他们猜对了数字。如果不是,那么他们没有猜到这个数字。这是游戏的前提。有人可以帮我修复我的代码,所以不管输出什么都不一样吗?为什么这个do-while循环没有产生正确的输出?
您是否尝试调试以查看'guess'在执行过程中有哪些值? – 2014-12-04 16:09:01
1)你为什么要求猜测输入两次?也看看你的if语句,如果猜测小于5,那么你打破了 – 2014-12-04 16:11:01
看看这个http://stackoverflow.com/questions/15273449/what-does-system-in-read-actually-return – Karunakar 2014-12-04 16:12:18