我希望我的程序一直问这个问题,直到它得到它可以使用的响应,特别是从 0 到 20 的数字。我在这门课上有很多其他的东西,所以这里有一小段摘录,其中 do-while 是(我已经命名了变量以及所有内容)。
public static void main(String[] args) {
do {
halp = 1;
System.out.println("What level is your fort?");
Scanner sc = new Scanner(System.in);
try {
fortLevel = Integer.parseInt(sc.nextLine());
}
catch(NumberFormatException e){System.out.println("Numbers only, 0-20"); halp = 0;
}
if(halp < 1) {
work = false;
}
if(halp > 1) {
work = true;
}
while(work = false);
}