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, feet, inches;
  9:                 double heightMeters, mass, BMI;
 10: 
 11:                 System.out.println("Enter your weight in pounds.");
 12:                 pounds = keyboard.nextInt();
 13:                 System.out.println("Enter your height in feet followed");
 14:                 System.out.println("by a space then additional inches.");
 15:                 feet = keyboard.nextInt();
 16:                 inches = keyboard.nextInt();
 17: 
 18:                 heightMeters = ((feet * 12) + inches) * 0.0254;
 19:                 mass = (pounds / 2.2);
 20:                 BMI = mass / (heightMeters * heightMeters);
 21: 
 22:                 System.out.println("Your BMI is " + BMI);
 23:                 System.out.print("Your risk category is ");
 24:                 if (BMI < 18.5)
 25:                         System.out.println("Underweight.");
 26:                 else if (BMI < 25)
 27:                         System.out.println("Normal weight.");
 28:             else if (BMI < 30)
 29:                     System.out.println("Overweight.");
 30:             else
 31:                     System.out.println("Obese.");
 32:         }
 33: }