为什么体重指数计算结果不正确?

时间:2016-02-10 08:04:03

标签: java

我做了以下程序,但我的输出与书中答案不符。

CASE

使用此代码我得到下面的输出:

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)

2 个答案:

答案 0 :(得分:3)

更改

double BMI = kg/(inches * inches);

double BMI = kg/(meters * meters);

答案 1 :(得分:0)

您必须决定是否要以英寸和磅为单位或以米为单位计算BMI。