gpt4 book ai didi

java - 未编译的基本Java程序

转载 作者:行者123 更新时间:2023-12-02 11:14:09 24 4
gpt4 key购买 nike

我已经编写了以下代码,但是由于错误,未成功编译。请指教!该错误显示“错误:不兼容的类型:不能将double转换为 bool(boolean) 值”以及“错误:不兼容的类型: bool(boolean) 不能被转换为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;
}


}

最佳答案

将您的isHealthy方法更改为

public static boolean isHealthy(double bmi) {
return bmi >= 18.5 && bmi < 25.0;
}

关于java - 未编译的基本Java程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53977841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com