Skip to content

Instantly share code, notes, and snippets.

@justinmusgrove
Created September 9, 2013 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinmusgrove/6490840 to your computer and use it in GitHub Desktop.
Save justinmusgrove/6490840 to your computer and use it in GitHub Desktop.
static String bmiDescription (double bmi) {
if (bmi < 18.5) {
return "You are underweight.";
} else {
if (bmi > 25) {
return "You are overweight.";
} else {
return "Your weight is optimal.";
}
}
}
static double calculateBMI (double height, double weight) {
return weight * 703 / (height * height);
}
// Variables
double weight; // The user's weight
double height; // The user's height
double bmi; // The user's BMI
// Calculate the user's body mass index.
bmi = calculateBMI(height, weight);
// Display the user's BMI.
System.out.println("Your body mass index (BMI) is " + bmi);
System.out.println(bmiDescription(bmi));
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Tell the user what the program will do.
System.out.println("This program will calculate your body mass index, or BMI.");
// Get the user's weight.
System.out.print("Enter your weight, in pounds: ");
weight = keyboard.nextDouble();
// Get the user's height.
System.out.print("Enter your height, in inches: ");
height = keyboard.nextDouble();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment