第二章第十四题(健康应用:计算BMI)(Health application: computing BMI)

    科技2022-07-10  116

    第二章第十四题(健康应用:计算BMI)(Health application: computing BMI)

    *2.14(健康应用:计算BMI)身体质量指数(BMI)是对体重的健康测量。它的值可以通过将体重(以千克为单位)除以身高(以米为单位)的平方得到。编写程序,提示用户输入体重(以磅为单位)以及身高(以英寸为单位),然后显示BMI。注意:1磅是0.45359237千克,1英寸是0.0254米。 下面是一个运行示例: Enter weight in pounds : 95.5 Enter height in inches : 50 BMI is 26.8573

    *2.14(Health application: computing BMI) Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI. Note one pound is 0.45359237 kilograms and one inch is 0.0254 meters. Here is a sample run: Enter weight in pounds : 95.5 Enter height in inches : 50 BMI is 26.8573

    参考代码:

    package chapter02; import java.util.Scanner; public class Code_14 { public static void main(String[] args) { double Pounds,Inches,Kilograms,Meters,BMI; System.out.print("Enter weight in pounds : "); Scanner PoundInput = new Scanner(System.in); Pounds = PoundInput.nextDouble(); System.out.print("Enter height in inches : "); Scanner InchInput = new Scanner(System.in); Inches = InchInput.nextDouble(); Kilograms = Pounds * 0.45359237; Meters = Inches * 0.0254; BMI = Kilograms / Math.pow(Meters, 2); System.out.println("BMI is " + BMI); } } 结果显示: Enter weight in pounds : 95.5 Enter height in inches : 50 BMI is 26.857257942215885 Process finished with exit code 0
    Processed: 0.011, SQL: 8