Java Program to Calculate Body Mass Index
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
//weight in kilograms
double weight = 70;
//height in meters
double height = 1.72;
// calculate bmi
double bmi = weight / (height * height);
// display bmi
System.out.println("Your BMI is " + bmi);
String outcome="";
if (bmi < 18.5)
{
outcome = "UNDERWEIGHT";
}
else if (bmi < 25)
{
outcome = "NORMAL";
}
else if (bmi < 30)
{
outcome = "OVERWEIGHT";
}
else if (bmi < 35)
{
outcome = "OBESE CLASS I";
}
else if (bmi < 40)
{
outcome = "OBESE CLASS II";
}
else
{
outcome = "OBESE CLASS III";
}
System.out.println("Your BMI result indicates " + outcome);
}
}
Output:
Your BMI is 23.661438615467823
Your BMI result indicates NORMAL
