• 计算身体质量指数


     1 package test2;
     2 
     3 import java.util.Scanner;
     4 
     5 public class ComputeAndInterpretBMI {
     6 
     7     public static void main(String[] args) {
     8         // TODO Auto-generated method stub
     9         Scanner input = new Scanner(System.in);
    10         
    11         System.out.println("Enter weight in pounds");
    12         double weight = input.nextDouble();
    13         
    14         System.out.println("Enter height in inches");
    15         double height = input.nextDouble();
    16         
    17         final double KILOGRAMS_PER_POUND = 0.45359237;
    18         final double METERS_PER_INCH = 0.0254;
    19         
    20         double weightInKilograms = weight * KILOGRAMS_PER_POUND;
    21         double heightInMeters = height * METERS_PER_INCH;
    22         double bmi = weightInKilograms/(heightInMeters * heightInMeters);
    23         
    24         System.out.println("BIM is " + bmi);
    25         if(bmi < 18.5)
    26             System.out.println("Underweight");
    27         else if(bmi < 25)
    28             System.out.println("Normal");
    29         else if(bmi < 30)
    30             System.out.println("Overweight");
    31         else 
    32             System.out.println("Obese");
    33     
    34 
    35     }
    36 
    37 }
  • 相关阅读:
    基础数据补充
    购物车
    小数据池、深浅拷贝和集合
    列表、元组和range
    小数据池、深浅拷贝和集合练习
    字典
    字符串练习
    列表练习
    练习
    字典练习
  • 原文地址:https://www.cnblogs.com/King-boy/p/10498285.html
Copyright © 2020-2023  润新知