public static void main(String [] args) {
Scanner input = new Scanner(System.in);
double dblNumber, dblSquare, dblSqrt;
String answer;
String answery = "yes";
String answern = "no";
while (true) {
System.out.println("Welcome to Squarez! Where we do the math for you.\nPlease input a number you would like us to do some math with.");
dblNumber = input.nextDouble();
dblSqrt = Math.sqrt(dblNumber);
dblSquare = Math.pow(dblNumber, 3);
System.out.println("" + dblSquare + " " + dblSqrt);
System.out.println("Would you like to continue?");
answer = input.nextLine();
if (answer.equals(answery)) {
System.out.println("You answered yes");
}
if (answer.equals(answern)) {
System.out.println("You answered no.");
System.exit(0);
}
}
}
該程序運行並完全忽略詢問用戶是否要繼續的提示。它會直接返回到第一個號碼的提示。爲什麼跳過這個?Java程序要求用戶繼續