计算身体质量指数

 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 }

 

posted @ 2019-03-08 21:09  殇之弑梦  阅读(309)  评论(0编辑  收藏  举报