gpt4 book ai didi

java - 我的 java bmi 计算器给出相同的答案

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

我正在尝试制作一个 bmi 计算器,但答案总是一样。

我试着输入数字 height=1.50 meter weight=100 kg但答案是体重不足

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double bmi = 0;
double weightinkg = 0;
double heightinmeter = 0;
String status = "";
System.out.println("Enter the weight in Kg :");
weightinkg = sc.nextDouble();
System.out.println("Enter the height in Meter : "); //enter the age
heightinmeter = sc.nextDouble();
if ((weightinkg <= 0) && (heightinmeter <= 0))
System.out.println("ERROR: Negative number");
double square = Math.pow(heightinmeter, 2);
bmi = weightinkg / heightinmeter;
if (bmi >= 0) {
if (bmi >= 0 && bmi <= 24) {
status = "Under Weight";
} else if (bmi >= 25 && bmi <= 29) {
status = "Healthy";
} else if (bmi >= 30 && bmi <= 34) {
status = "Overweight";
} else
status = "Obese";
}
else
System.out.println("Invalid BMI (number must be positive");
System.out.printf("Hello, your status is %s ! Please come again!", status);
}

最佳答案

您没有使用正方形。应该是

    double square = Math.pow(heightinmeter, 2);
bmi = weightinkg / square;

关于java - 我的 java bmi 计算器给出相同的答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65936771/

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