布尔值不接受Scanner中的响应?

时间:2018-06-26 05:35:34

标签: java object if-statement boolean java.util.scanner

我的程序中的扫描仪出现问题。

System.out.print("Do you smoke?(y/n): ");       
String isSmoker = console.nextLine();
boolean smoker = false;
if (isSmoker.equalsIgnoreCase("y")) {
    smoker = true;
}

程序的这一部分不允许我输入问题的答案,而只是跳到程序的下一部分,然后结束。在程序的后面,有一些计算BMI并获取保险费用的方法。当我运行程序时,会发生这种情况,例如:

Welcome to our new Health Plan! 
When prompted, enter the health plan in which you would like to enroll:
E (E-mployee), C (Employee/C-hildren), S (Employee/S-pouse), F (Employee/F-amily).
You will be asked whether or not you smoke and for your weight and height.
If you choose plan S or F, you will be asked whether your spouse smokes and for
his/her weight and height. Your monthly health plan premium will then be displayed.
Heath Plan (E-mployee, C-hildren, S-pouse, F-amily): 
C
Weight (lb): 128
Height (in): 62
Do you smoke?(y/n): 23.408949011446413Monthly Health Plan Premium: 245
MacBook-Pro:src cs$ 

如何使吸烟问题在控制台中接受答复?我要使用nextBoolean而不是nextLine吗?

0 个答案:

没有答案