# Java program to calculate Body Mass Index (BMI)

Java 8Object Oriented ProgrammingProgramming

#### Complete Java Programming Fundamentals With Sample Projects

98 Lectures 7.5 hours

#### Get your Java dream job! Beginners interview preparation

85 Lectures 6 hours

#### Core Java bootcamp program with Hands on practice

Featured

99 Lectures 17 hours

The Body Mass Index is the body mass in kilogram divided by the square of body height in meters. This is expressed as kg/m^2.

A program that calculates the Body Mass Index (BMI) is given as follows.

## Example

import java.util.Scanner;
public class Example {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Input weight in kilogram: ");
double weight = sc.nextDouble();
System.out.print("Input height in meters: ");
double height = sc.nextDouble();
double BMI = weight / (height * height);
System.out.print("The Body Mass Index (BMI) is " + BMI + " kg/m2");
}
}

## Output

Input weight in kilogram: 55
Input height in meters: 1.5
The Body Mass Index (BMI) is 24.444444444444443 kg/m2

Now let us understand the above program.

The values of the weight and height are obtained from the user in kilogram and meters respectively. The code snippet that demonstrates this is given as follows −

Scanner sc = new Scanner(System.in);
System.out.print("Input weight in kilogram: ");
double weight = sc.nextDouble();
System.out.print("Input height in meters: ");
double height = sc.nextDouble();

Then the Body Mass Index is calculated using the formula BMI = weight / (height * height). Finally the values of the Body Mass Index is displayed. The code snippet that demonstrates this is given as follows −

double BMI = weight / (height * height);
System.out.print("The Body Mass Index (BMI) is " + BMI + " kg/m2");
Updated on 25-Jun-2020 14:19:29