出于我自己的好奇心,我在朋友的代码上问这个问题。
它获取用户输入并使用它计算 BMI。虽然数字出现错误,而且我不懂 java,所以我很想知道为什么。
要遵循的代码:
import java.util.Scanner;
public class ComputeBMI{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
final double INCHES_PER_FEET = 12; // Constant
System.out.printf("Enter weight in pounds: ");
double weight = in.nextDouble();
System.out.printf("Enter feet: ");
int feet = in.nextInt();
System.out.printf("Enter inches: ");
int inches = in.nextInt();
double totalHeight = (feet * INCHES_PER_FEET) + inches;
double bmi = (weight /(totalHeight * totalHeight)) * 720;
System.out.println("BMI is " + bmi);
if (bmi < 18.5)
System.out.println("Underweight");
else if (bmi < 25)
System.out.println("Normal");
else if (bmi < 30)
System.out.println("Overweight");
else
System.out.println("Obese");
身高 5 英尺 10 英寸,体重 140 磅的用户的输出结果如下:
Enter weight in pounds: 140
Enter feet: 5
Enter inches: 10
BMI is 984.297411494823
Obese
应该在20左右,这很正常
谁能告诉我我朋友做错了什么?
谢谢。