BMI Calculator in Java


In this blog, we will learn to create a simple BMI calculator in Java programming language where the BMI value is calculated based on the inputs given by the user in metric units.

Body Mass Index

What is BMI?

BMI stands for Body Mass Index. It is used to measure the body mass based on the height and weight of the individual. The range of BMI classifies individuals as underweight, normal or overweight. The main BMI categories are shown below:

Body Mass Index categories

Formula for Calculating BMI in Metric Units

The formula for calculating BMI value is:

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

For example, let us consider height = 1.5m and weight = 90kg

BMI = 90 / (1.5 * 1.5) = 40 (Obese).

How It Works?

  1. Input the weight in kg and height in cm from the user.
  2. A static method CalculateBMI() is called by passing height and weight as its arguments.
  3. The BMI value is calculated by dividing weight in kg with square of the height in meters.
  4. The height in centimeters can be converted to height in meters by dividing the height value by 100 (1 m = 100 cm).
  5. The obtained BMI value is displayed on the console.
  6. Also, if-else statements are used to categorize the BMI values. So, according to the obtained BMI value, the if-else statements will be executed.

Source Code

Here is the complete source code for Java program that calculates the BMI value based on the inputs given by the user in metric units. Also, note that the height input is to be given in centimeters.

Source code for BMI program


Here is a sample output of the above program.

Output of BMI

Are you looking to master coding and crack top company interviews? Go ahead and try GUVI’s Pro Subscription to help you with everything needed to build a strong Technical Career.

Know more about GUVI:

Also, download GUVI’s app to learn the latest IT skills in vernacular languages.

Love podcasts or audiobooks? Learn on the go with our new app.

Handling Google’s favorite rodent — kickstarting your Go project

Kubernetes Deployment and Testing Strategies

Google T5 Translation as a Service in Just 7 lines of Codes

EPISODE #60: Why Lasting Automation Success and Competitive Advantage Require Process Excellence

How to add a Github third-party authentication to your Rails MVC

PDF Download@ Proxmox Cookbook Read #book @ePub

Reset phase at Encora Apprenticeship— Week 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Baruni Priya T S

Baruni Priya T S

More from Medium


All new Java 8 — time API — LocalDate

Why Java is platform independent

How to find factorial of any number in java..