**Java Programs**

➤ Check Even Number

➤ Check Odd Number

➤ Java Even-Odd

➤ Greatest of 3 numbers

➤ Exponents in Java

➤ Java Leap Year Program

➤ Display Multiplication Table

➤ Reverse of a number

➤ Factors of a Number

➤ Java LCM of 2 Numbers

➤ Java HCF of 2 Numbers

➤ Quadratic Equation Program

➤ Square Root of Number

➤ Perfect Square Program

➤ Simple Calculator Program

➤ BMI Calculator Java

➤ Factorial of a Number

➤ Factorial Using Recursion

**#**Java Programs to Find Sum

**#**Java Conversion Programs

**#**Java Program on Series

**#**Java Pattern Programs

**#**Java Number Programs

**Java Array Programs**

**Java String Programs**

Previously we have developed a Java program for Simple calculator using switch cases and methods. Now in this post, we will develop a Java program for a BMI calculator.

The BMI stands for Body Mass Index. It is a measure of health based on height and weight. It can be calculated by taking the weight in kilograms and dividing it by the square of your height in meters.

Formula for Calculating BMI in Metric Units,

*BMI = (Weight in Kg) / (Height in Meters * Height in Meters)*

For example,

weight = 75 kg, height = 1.5 m

BMI = 75 / (1.5*1.5) = 33.33

Using the range of BMI, individuals are classified as underweight, normal or overweight. Its value is in a specific range for a healthy individual. The following table shows the main BMI categories,

BMI Range | Category |

< 18.5 | Thinness |

18.5 – 25 | Normal |

25 – 30 | Overweight |

> 30 | Obese |

BMI calculator finds whether the person is underweight, normal, overweight, or obese. The person who wants to lose their want can use a weight loss calculator which can tell the daily caloric requirements, and many easy tips to lose weight.

## Java program for BMI calculator

```
import java.util.Scanner;
public class BMICalculator {
// method to check bmi category
public static String bmiCategory(double weight,
double height) {
// calculate bmi
double bmi = weight / ( height * height) ;
// check range
if(bmi < 18.5)
return "Thinness";
else if(bmi < 25)
return "Normal";
else if(bmi < 30)
return "Overweight";
else
return "Obese";
}
public static void main(String[] args) {
// declare variables
double weightInKg = 0.0f;
double heightInMeters = 0.0f;
String result = null;
// create Scanner class object to
// take input
Scanner scan = new Scanner(System.in);
System.out.print("Enter weight in Kg: ");
weightInKg = scan.nextDouble();
System.out.print("Enter height in meters: ");
heightInMeters = scan.nextDouble();
// calculate BMI index
result = bmiCategory( weightInKg,
heightInMeters );
// display result
System.out.println(result);
// close Scanner class object
scan.close();
}
}
```

The output for the different-test cases are:-

Enter weight in Kg: 45

Enter height in meters: 1.37

Normal

Enter weight in Kg: 80

Enter height in meters: 1.7

Overweight

Normally we measure height in feet and inches. So, you can take the height in feet and inches and later convert it into the meters. Below code converts feet and inches to meters.

```
int feet;
int inches;
System.out.println("Enter height in feet and inches,");
System.out.print("Feet:: ");
feet = scan.nextInt();
System.out.print("Inches:: ");
inches = scan.nextInt();
// Convert feet and inches to meter
heightInMeters = ((feet * 12) + inches) * 0.0254;
```

Output:-

Enter weight in Kg: 60

Enter height in feet and inches,

Feet:: 5

Inches:: 4

Normal

Similar Java programming examples