【发布时间】:2017-01-21 06:55:11
【问题描述】:
我不久前才开始编程,我真的很想学习更多。现在,我正在创建一个小的“if-else”、“while-do”场景,用户将使用正确的整数来回答问题。我遇到了麻烦,每当我点击这部分代码时:
if (chopperCrash > 100) {
System.out.println("That's not possible!");
System.out.println("Hurry and re-enter a new value before we crash!");
continue;
它不断循环打印的文本。有人可以在这个特定项目上帮助我,并向我详细解释“if-else”和“while-do”语句的正确位置吗?感谢您的任何帮助。如果这已经得到回答,我很抱歉,而且我太密集而无法理解其他先前提出的问题。这是我的完整代码块:
import java.util.Scanner;
public class FirstClass {
public static void main (String[] args){
System.out.println("The chopper is going down because your lack of experience.");
System.out.println("How much throttle are you going to give it?");
System.out.println("(enter a number between 1 and 100)");
Scanner FirstScan = new Scanner(System.in);
int number = FirstScan.nextInt();
int chopperCrash = number;
while (true){
if (chopperCrash >= 60 && chopperCrash <= 100){
System.out.println("Looks like we'll make it another day!");
break;
}
else{
if (chopperCrash > 100) {
System.out.println("That's not possible!");
System.out.println("Hurry and re-enter a new value before we crash!");
continue;
}
else{
if (chopperCrash <= 59) {
System.out.println("Not enough throttle!");
System.out.println("We're going down!");
break;
}
}
}
}
}
}
【问题讨论】:
标签: java if-statement while-loop do-while