import java.util.Scanner;
import static java.lang.System.out;
public class TestingStuf2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
out.println("Enter a number");
int number = keyboard.nextInt();
while (number < 10) {
if (number < 10) {
out.println("This number is too small.");
keyboard.nextInt();
}else{
out.println("This number is big enough.");
}
}
keyboard.close();
}
}
我只是有点麻烦循环这段代码。我刚开始学习Java,这些循环一直困扰着我。当我运行这个程序时,如果输入的数字小于10,我会看到“”这个数字太小“的消息,然后它允许我再次输入,但是如果我输入一个大于10的数字,如果我输入的第一个数字大于10,我根本没有收到消息,程序刚刚结束,为什么会发生这种情况?我怎样才能让循环在我的Java程序中工作?
你解释了你得到的行为 - 它与你的期望有什么不同? – Blorgbeard
更清楚发生什么事情与您预期发生的事情。正如所写,很难回答你的问题。 – nhouser9