In: Computer Science
Create a BMI calculator that reads the user’s weight and height (providing an option for the user to select which formula to use), and then calculates and displays the user’s body mass index. Also, display the BMI categories and their values from the National Heart Lung and Blood Institute: http://www.nhlbi.nih.gov/health/educational/lose_wt/BMI/bmicalc.htm (Links to an external site.) so the user can evaluate his/her BMI.
Java Version
import java.util.*; public class BMICalc { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("height (in feet)? "); double feet = console.nextInt(); System.out.print("height (in inches)? "); double height = console.nextDouble(); height = feet*12 + height; System.out.print("weight (in pounds)? "); double weight = console.nextDouble(); double bmi = (weight * 703 / height / height); System.out.printf("BMI = %.1f\n",bmi); if (bmi < 18.5) { System.out.println("underweight"); } else if (bmi < 25) { System.out.println("normal"); } else if (bmi < 30) { System.out.println("overweight"); } else { System.out.println("obese"); } } }