Java数据类型练习故障排除

时间:2018-03-20 18:12:28

标签: java

我在显示计算体重指数的结果时遇到问题。我不确定为什么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);

  }
}

1 个答案:

答案 0 :(得分:1)

您应该将所有整数输入到双打,以便获得结果。

实际上这对你有用

bodyMassIndex = ((double)weight / (height * height)) * 703;