Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and diving by the square of your height in meters (weight/height2). The interpretation of BMI for people 16 years or older is as follows:
BMI Interpretation
below 16 serious underweight
16-18 underweight
18-24 normal weight
24-29 overweight
29-35 seriously overweight
above 35 gravely overweight
Write a program that prompts the user to enter weight in kilograms and height in meters.
weight in kilograms (type of double) and height in meters (type of double)
BMI Interpretation
The formula for BMI is (weight in kilograms)/(height in meters)2.
We know the height and weight from the input. So, we can calculate the BMI easily.
Using BMI, we can interpret using if-else control structure.
public class BMI {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
int weight;
int height;
int bMI;
System.out.print ("Enter Your Weight in Kg: ");
weight = input.nextInt();
System.out.print ("Enter Your Height in Meters: ");
height = input.nextInt();
bMI = (weight) / (height * height);
System.out.printf ("Your Body Mass Index (BMI) is %d\n\n", bMI);
if (bMI < 16)
System.out.println ("You are seriously underweight");
else if (bMI > 35)
System.out.println ("You are gravely Overweight");
}
}
Save and run this program. What is your output?
In this program the type of input is int. Suppose out weight and height are rational numbers.
Change the data type for weight, height and bMI to double.
And suppose method to read the double data type also need to change.
Complete your program by adding another BMI interpretation.