Created
May 4, 2013 12:30
-
-
Save jimmy087/5517356 to your computer and use it in GitHub Desktop.
Compute Body Mass Index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| //Compute BMI | |
| public class ComputeBMI { | |
| public static void main(String[] args) { | |
| Scanner input = new Scanner(System.in); | |
| System.out.print("Please enter your weight in pounds: "); | |
| double weightPound = input.nextDouble(); | |
| System.out.print("Please enter your height in inches: "); | |
| double heightInch = input.nextDouble(); | |
| double weightKilograms = weightPound * 0.45359237; | |
| double heightMeter = heightInch * 0.0254; | |
| double bodyMassIndex = weightKilograms / Math.pow(heightMeter, 2); | |
| System.out.print("Your Body Mass Index is: " + bodyMassIndex); | |
| if (bodyMassIndex < 16) System.out.println(" You are seriously underweight."); | |
| else if (bodyMassIndex < 18) System.out.print(" You are underweight."); | |
| else if (bodyMassIndex < 24) System.out.print(" You are normal weight."); | |
| else if (bodyMassIndex < 29) System.out.print(" You are overweight."); | |
| else if (bodyMassIndex < 35) System.out.print(" You are seriously overweight."); | |
| else System.out.print(" You are gravely overweight."); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment