它的值可以通过将体重(以公斤为单位)除身高(以米为单位)的平方值得到。编写程序,提示用户输入体重(以磅为单位)以及身高(以英寸为单位),然后显示BMI。
注意:一磅是0.45359237公斤,一英寸是0.0254米。
下面是一个运算示例:
Enter weight in pound: 95.5
Enter hight in inches: 50
BIM is 26.8573
package Second;
import java.util.Scanner;
public class Code14 {
public static void main(String[] args) {
System.out.print("Enter weight in pound: ");
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
System.out.print("Enter hight in inches: ");
double hight = input.nextDouble();
double BIM = 0;
BIM = weight * 0.45359237 / (hight * hight * 0.0254 * 0.0254);
System.out.println(" BIM is " + BIM);
}
}
输出
Enter weight in pound: 95.5 Enter hight in inches: 50 BIM is 26.857257942215885