gpt4 book ai didi

java - 为什么 body 质量指数计算会导致错误的结果?

转载 作者:行者123 更新时间:2023-12-01 21:50:19 27 4
gpt4 key购买 nike

我执行了以下程序,但我的输出与书本答案不匹配。

import java.util.Scanner;

public class BMI_Index {
public static void main (String [] args) {
Scanner kbd = new Scanner(System.in);
System.out.print("Enter weght in pound: ");
double pound = kbd.nextDouble();
double kg = pound * 0.45359237;
System.out.print("Enter hight in inches: ");
double inches = kbd.nextDouble();
double meters = inches * 0.0254;
double BMI = kg/(inches * inches);
System.out.println("BMI is " + BMI);
if (BMI < 18.5) {
System.out.print("Underweight");
}
if (BMI >= 18.5 && BMI < 25.0) {
System.out.print("Normal");
}
if (BMI >= 25.0 && BMI < 30.0) {
System.out.print("Overweight");
}
if (BMI >= 30.0) {
System.out.print("Obese");
}
}
}

通过这段代码,我得到下面的输出:

Weight: 146 (inches)
Height: 70 (inches)
Result: 0.013515201228571428 (BMI)

我的书的预测输出是:

Weight: 146 (inches)
Height: 70 (inches)
Result: 20.948603801493316 (BMI)

最佳答案

改变

double BMI = kg/(inches * inches);

double BMI = kg/(meters * meters);

关于java - 为什么 body 质量指数计算会导致错误的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35309713/

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