这是弹出的错误:
Riccio_Lesson5.java:88: error: illegal start of expression
}else if(bmi == 18.5 & <= 24.9){
^
Riccio_Lesson5.java:91: error: illegal start of expression
}else if(bmi == 25.0 & <= 29.9){
^
这是此代码:
if(bmi < 18.5){
System.out.print(", indicating your weight is in the\nUnderweight category for adults of your height.");
System.out.print("\n\nTalk with your healthcare provider to determine possible causes of underweight and if you need to gain weight.");
}else if(bmi == 18.5 & <= 24.9){
System.out.print(", indicating your weight is in the \nNormal category for adults of your height.");
}else if(bmi == 25.0 & <= 29.9){
System.out.print(", indicating your weight is in the Overweight category for adults of your height.");
}else if(bmi >= 30.0){
System.out.print(", indicating your weight is in the Obese category for adults of your height.");
}
我想说的是,如果bmi等于18.5或小于或等于24.9,则您的bmi将显示为正常/如果bmi等于25小于或等于29.9,则表明您超重
答案 0 :(得分:2)
您不能像在自然语言中那样,用Java留下比较表达式的左侧。它总是需要明确的。 “ BMI大于或等于18.5且小于或等于24.9”必须转换为:
bmi >= 18.5 && bmi <= 24.9
请注意,这里我使用>=
来捕获大于或等于18.5的值。我还使用了&&
,尽管它&
可以很好地用于逻辑运算,但是它通常用于短路的逻辑连接。
您可能还想使用bmi < 25.0
而不是bmi <= 24.9
,因为您的下一个else if
条件以bmi >= 25.0
开头(或将以else if
开头),并且您希望捕获诸如24.95之类的值,这些值不会被您当前的逻辑所捕获。
下一个dscacheutil -flushcache
条件需要类似的更改。