我已经编写了以下代码,但是由于错误,未成功编译。请指教!错误显示“错误:不兼容的类型:不能将double转换为布尔值”以及“错误:不兼容的类型:布尔不能被转换为double值”。
class BMITest {
public static void main(String[] args) {
showData(fullName("John", "McDermott"), 178, 74.3);
}
public static void showData(String name, double height, double weight) {
double bmi = BMInum(height, weight);
System.out.println("His name is " + name + ", and his BMI is " + bmi);
if (isHealthy(bmi)) {
System.out.println("He is healthy.");
} else {
System.out.println("He's not healthy.");
}
}
public static String fullName(String first, String last) {
return first + " " + last;
}
public static double BMInum(double height, double weight) {
return weight / height / height * 10000;
}
public static double isHealthy(double bmi) {
return bmi >= 18.5 && bmi < 25.0;
}
}
答案 0 :(得分:1)
将您的isHealthy
方法更改为
public static boolean isHealthy(double bmi) {
return bmi >= 18.5 && bmi < 25.0;
}
答案 1 :(得分:0)
isHealthy返回双精度值而不是布尔值。由于您需要在if语句剧院中使用它。