【发布时间】:2019-09-21 13:55:46
【问题描述】:
我正在创建一个 bmi 计算器并使用身高和体重公式。我不断收到一个错误,最后说 nan obese,我不知道我缺少什么或需要编辑什么。任何帮助,将不胜感激。
输出错误:
Enter Weight in pounds: 150
Enter height (ft.):
6
Enter height (in.):
7
Your BMI is: NaN
Obese
BMI公式:
BMI = (703 * weightInPounds) / heightInInches^2
代码:
import java.util.Scanner;
public class Bmi_Calc {
public static void main(String[] args) {
// TODO Auto-generated method st
Scanner input = new Scanner(System.in);
//double weight;
double weightInPounds;
int feet;
int inches;
//int weightInPounds;
int heightInInches;
double height;
System.out.print("Enter Weight in pounds: ");
double weight = input.nextDouble();
System.out.println("Enter height (ft.): ");
feet = input.nextInt();
System.out.println("Enter height (in.): ");
inches = input.nextInt();
weightInPounds = 0;
heightInInches = 0;
double bmi = (703 * weightInPounds) / Math.pow(heightInInches, 2.0);
double heightMeters = ((feet * 12) + inches) * .0254;
System.out.println("Your BMI is: " + bmi);
if (bmi < 18.5) {
System.out.println("Underweight.");
}
if ((bmi >= 18.5) && (bmi < 24.9)) {
System.out.println("Normal weight");
}
if ((bmi >= 25) && (bmi < 29.9)) {
System.out.println("Overwight");
}
else {
System.out.println("Obese");
}
input.close();
}
}
【问题讨论】:
标签: java arrays if-statement double