Source of BMI.java


  1: import java.util.Scanner;
  2: 
  3: public class BMI
  4: {
  5:         public static void main(String[] args)
  6:         {
  7:                 Scanner keyboard = new Scanner(System.in);
  8:                 int pounds;
  9:                 int feet;
 10:                 int inches;
 11:                 double heightMeters;
 12:                 double mass;
 13:                 double BMI;
 14: 
 15:                 System.out.println("Enter your weight in pounds.");
 16:                 pounds = keyboard.nextInt();
 17:                 System.out.println("Enter your height in feet followed");
 18:                 System.out.println("by a space then additional inches.");
 19:                 feet = keyboard.nextInt();
 20:                 inches = keyboard.nextInt();
 21: 
 22:                 heightMeters = ((feet * 12) + inches) * 0.0254;
 23:                 mass = (pounds / 2.2);
 24:                 BMI = mass / (heightMeters * heightMeters);
 25: 
 26:                 System.out.println("Your BMI is " + BMI);
 27:                 System.out.print("Your risk category is ");
 28:                 if (BMI < 18.5)
 29:                         System.out.println("Underweight.");
 30:                 else if (BMI < 25)
 31:                         System.out.println("Normal weight.");
 32:             else if (BMI < 30)
 33:                     System.out.println("Overweight.");
 34:             else
 35:                     System.out.println("Obese.");
 36:         }
 37: }