【发布时间】:2018-03-20 18:12:27
【问题描述】:
我在显示体重指数计算结果时遇到问题。我不确定为什么 bodyMassIndex 变量没有执行计算并显示结果。感谢您的任何反馈。
// Write a Java program to compute body mass index (BMI).
public class Exercise3 {
public static void main (String [] args) {
// Variable Declaration
int height;
int weight;
double bodyMassIndex;
Scanner input = new Scanner (System.in);
// Obtain user input
System.out.println("What is your remaining height in inches: ");
height = input.nextInt();
System.out.println("What is your weight (in pounds): ");
weight = input.nextInt();
// Perform computations
bodyMassIndex = (weight / (height * height)) * 703;
// Display Results
System.out.println("Your Body Mass Index is: " + bodyMassIndex);
}
}
【问题讨论】:
-
为什么 bodyMassIndex 变量没有执行计算并显示结果——您预计会发生什么,正在发生什么?你认为这是为什么?您是否尝试过将
height和weight定义为double(所以您不只是在进行整数运算,然后分配给双精度数)
标签: java