Skip to content

Instantly share code, notes, and snippets.

@jimmy087
Created May 4, 2013 12:30
Show Gist options
  • Save jimmy087/5517356 to your computer and use it in GitHub Desktop.
Save jimmy087/5517356 to your computer and use it in GitHub Desktop.
Compute Body Mass Index
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