赞
踩
体重指数(BMI)是以体重来衡量的健康程度。其值可以通过将体重(以千克为单位)除以身高(以米为单位)的平方得到。编写程序,提示用户输人体重(以磅为单位)以及身高(以英寸为单位),然后显示 BMI。注意:1磅等于 0.45359237 千克,1英寸等于0.0254 米。下面是一个运行示例:
Enter weight in pounds : 95.5
Enter height in inches : 50
BMI is 8573
- import java.util.Scanner;
-
- /**
- * @author duanjiankun
- */
- public class ComputeBMI {
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- System.out.println("Enter weight in pounds : ");
- double weightInPounds = input.nextDouble();
- System.out.println("Enter height in inches : ");
- double heightInInches = input.nextDouble();
- //将磅转化为千克,将英寸转化为米
- double weightInKilograms = weightInPounds * 0.45359237;
- double heightInMeters = heightInInches * 0.0254;
- double BMI = weightInKilograms / Math.pow(heightInMeters,2);
- System.out.println("BMI is " + BMI);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。