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

第二章第十四题(健康应用:计算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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值