【发布时间】:2015-12-08 17:52:19
【问题描述】:
while 循环和 if 语句在第一次迭代中工作。完成后,它会打印“你想要另一个时间吗?”我输入“Y”程序终止,我不知道为什么。我的逻辑和语法似乎是正确的,但总是有我无法亲眼看到的缺陷。如果有人能指出缺陷,我将不胜感激。
while (!check) {
str = in.nextLine();
if (in.hasNextLine() && str.equals("Y")) {
hours = ran.nextInt(11) + 1;
minutes = ran.nextInt(60);
if (minutes < 10) {
System.out.println(hours + ":" + "0" + minutes);
} else {
System.out.println(hours + ":" + minutes);
}
System.out.println("Do you want another time?");
} else {
check = true;
}
}
【问题讨论】:
标签: java if-statement while-loop