8+ Java BMI Calculator Programs

This post contains a total of 8+ Java BMI Calculator Program Examples with Source Code. All these BMI ( Body mass index ) Calculator Programs are made using Java.

You can use the source code of these examples with credits to the original owner.

Java BMI Calculator Programs

1. BMI Calculator by Markie Alicia

Made by Markie Alicia. Source

```What is your weight ?
50
What is your height?
1.5
You are obese :```
``````import java.util.Scanner;

public class Program
{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("What is your weight ? ");

double userWeight = input.nextDouble();

System.out.print("What is your height? ");

double userHeight = input.nextDouble();

final double KILOGRAMS_PER_LB = 0.453;
final double METERS_PER_INCH = 0.025;

double userWeightKg = userWeight *  KILOGRAMS_PER_LB;
double userHeightM = userHeight * METERS_PER_INCH;

double userBMI = userWeightKg / (userHeightM * userHeightM);

System.out.println("Your BMI is" + userBMI);

if ( userBMI < 18.5) {

System.out.println(" Your are underweight ! ");

}

else if( userBMI < 27){

System.out.println("You are normal !");
}

else if (userBMI < 31){
System.out.println("You are overweight ");
}

else {
System.out.println("You are obese :");

}

}
}``````

2. BMI Calculator by Dark Prince

Made by Dark Prince. Source

```Enter your weight in kilo grams
60
Enter your height in meters
1.6
Your Body Mass Index Is 23.437499999999996```
``````import java.util.Scanner;

class MyClass {
public static void main(String[ ] args) {
System.out.println(" Enter your weight in kilo grams");
Scanner W = new Scanner(System.in);
double weight = W.nextDouble();

System.out.println(" Enter your height in meters");
double height = W.nextDouble();

double bmi = weight / ( height * height );

System.out.println("Your Body Mass Index Is " + bmi);
}
}``````

3. BMI Calculator by Joshua Wood

Made by Joshua Wood. Source

```2

Please enter weight in kilograms: 55
Please enter height in meters: 1.55

Your BMI is: 22.9!```
``````import java.util.Scanner;

public class Application {
// Main method
public static void main(String[] args) {
// Initialize scanner to scan
Scanner scan = new Scanner(System.in);

// Constant (703 is part of the equation and is never changed)
final int NUM_MULT = 703;

// Variable declarations
int userChoice;
int error = 1;
double weightInPounds;
double heightInInches;
double weightInKilograms;
double heightInMeters;
double BMI;

// Prompt for calculation mode
System.out.println("Which formula would you like to use (lbs/inch or kg/meters)?");
System.out.println("\nPlease enter 1 for lbs and 2 for kgs: ");

// Get calculation mode
userChoice = scan.nextInt();

// Prompt for weight and height (lbs/inch)
if (userChoice == 1) {
System.out.println();
// Get weight from user
System.out.println("Please enter weight in pounds: ");
weightInPounds = scan.nextDouble();
// Get height from user
System.out.println("Please enter height in inches: ");
heightInInches = scan.nextDouble();
// Equation for BMI calculation
BMI = (NUM_MULT * weightInPounds) / Math.pow(heightInInches, 2);
// Display BMI value
System.out.printf("\nYour BMI is: %.1f!\n", BMI);
}

// Prompt for weight and height (kg/meters)
else if (userChoice == 2) {
System.out.println();
// Get weight from user
System.out.println("Please enter weight in kilograms: ");
weightInKilograms = scan.nextDouble();
// Get height from user
System.out.println("Please enter height in meters: ");
heightInMeters = scan.nextDouble();
// Equation for BMI calculation
BMI = weightInKilograms / Math.pow(heightInMeters, 2);
// Display BMI value
System.out.printf("\nYour BMI is: %.1f!\n\n", BMI);
}

// User must enter a valid choice
else {
System.out.println("ERROR!! INVALID ENTRY!");
error = 0; // Exits program
}
// Call categoryValues if there is a valid entry
if (error == 1)
categoryValues();

scan.close();
}

// Display BMI category
public static void categoryValues() {
System.out.println("\nBMI Categories: \n");
System.out.println("Underweight = 18.5");
System.out.println("Normal weight = 18.5 - 24.9");
System.out.println("Overweight = 25 - 29.9");
System.out.println("Obesity = BMI of 30 or greater");
}

}``````

4. BMI Calculator by Sanaz

Made by Sanaz. Source

```Tell me how tall you are: 1.6

Now let me know how much you weigh: 55

Your BMI is: 21.484374999999996

Congrates! You're normal.```
``````import java.util.Scanner;
import java.lang.Math;

public class ChapterTwoTest {

public static void main(String[] args) {
System.out.println("Welcome to the BMI Calculator using metric measurement:)\n");
System.out.println("Tell me how tall you are:");

Scanner scanner = new Scanner(System.in);
double height = scanner.nextDouble();
// double height = 1.63;
System.out.println();

System.out.println("Now let me know how much you weigh:");
int weight = scanner.nextInt();
// int weight = 58;
System.out.println();

double BMI = weight / Math.pow(height, 2);
System.out.println("Your BMI is: " + BMI);
System.out.println();

if (BMI < 18.5) {
System.out.println("Darling! You're underweight...");
System.out.println("Do some exercises.");
}
else if (BMI >= 18.5 && BMI < 24.9) {
System.out.println("Congrates! You're normal.");
System.out.println("Keep up the good work!");

} else if (BMI >= 25 && BMI < 29.9) {
System.out.println("Oh... you're overweight");
System.out.println("Why not eating a balanced diet?!");
} else {
System.out.println("Unfortunately you're obese.");
System.out.println("Move your body for your own sake!");
}

}

}``````

5. BMI Calculator by BaumBruh

Made by BaumBruh. Source

```50
1.5
Your BMI is: 22.22222222222222```
``````import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
double height, weight, bmi;
Scanner scan = new Scanner(System.in);
weight = scan.nextDouble();
height = scan.nextDouble();
bmi = weight / (double) (Math.pow(height, 2));
System.out.println("Your BMI is: " + bmi);
}
}``````

6. BMI Calculator by Mateusz Jurkiewicz

Made by Mateusz Jurkiewicz. Source

```Enter your weight in kg: 60
Enter your height in m: 1.6
Your BMI is 23.437499999999996 It's ok!```
``````import java.util.Scanner;
public class calculator {

void print(){
double height;
double weight;
double bmi;
Scanner sc = new Scanner(System.in);
System.out.println("Enter your weight in kg: ");
weight=sc.nextDouble();
System.out.println("Enter your height in m: ");
height=sc.nextDouble();
bmi = weight/(height*height);

if (bmi < 18.5){
System.out.println ("Your BMI is " + bmi + " You are too light.");
} else if (bmi>24.9){
System.out.printf ("Your BMI is " + bmi + " You are too heavy");
} else if (bmi>=18.5||bmi<=24.9){
System.out.println("Your BMI is " + bmi + " It's ok!");
}

}
}

public class BMI {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
calculator cal = new calculator();
cal.print();
// TODO code application logic here
}

}``````

7. BMI Calculator by Orango Mango

Made by Orango Mango. Source

```Enter height (cm): 160
Enter weight (kg): 60
Your BMI is: 23.44
You are normalweight```
``````/*
* Inputs are:
* 1. weight in kg,
* 2. height in cm
*/

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.io.*;

public class BMICalc {

/**
* method that calculates the BMI
* @param height
* @param weight
* @return bmi (weight / height ^ 2)
*/
public static double calcBMI(int height, int weight){

double Mheight = height / 100.0;

double bmi = weight / ((double) Mheight * Mheight);
return bmi;
}
/**
* Main method
* @throws IOException
*/
public static void main(String[] args) throws IOException {
System.out.println("Enter height (cm): ");

/**
* height variable
*/
System.out.println("Enter weight (kg): ");

/**
* weight variable
*/

/**
* bmi variable
*/
double bmi = calcBMI(height, weight);

NumberFormat formatter = new DecimalFormat("##.##");

System.out.println("Your BMI is: "+formatter.format(bmi));

if (bmi < 18.5){
System.out.println("You are underweight");
} else if (bmi < 25){
System.out.println("You are normalweight");
} else if (bmi < 30){
System.out.println("You are overweight");
} else {
System.out.println("You highly overweighted");
}
}
}``````

8. BMI Calculator by Mayank Dhull

Made by Mayank Dhull. Source

```40
140
You are normal. Your BMI is 20.408165```
``````import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Float a = sc.nextFloat();
Float b = sc.nextFloat();
Float c = b * 0.01f;
Float bmi = a/(c*c);
if(bmi>=25.0){
System.out.println("You are overweight. Your BMI is " + bmi);
}
else if(bmi<=18.49){
System.out.println("You are underweight. Your BMI is " + bmi);
}
else {
System.out.println("You are normal. Your BMI is " + bmi);
}
}
}``````

9. Java BMI Calculator by Himadri Shekhar Ray

```60
55
BMI=30.743740165289253
Your BMI very high. It is OBESE.
You have to loose weight KG:11.209579838514514```
``````import java.util.Scanner;

class MyClass {
public static void main(String[ ] args) {

double hight, weight, conhi, sqhi, BMI;

Scanner input = new Scanner(System.in);

//input weight in KG
weight =input.nextDouble();

//input hight in Inch.
hight =input.nextDouble();

conhi = hight/39.37;

sqhi = conhi*conhi;

BMI = weight/sqhi;

System.out.println("BMI=" +BMI);

double uw = 23*sqhi-weight;

double ow = weight-25*sqhi;

if(BMI<18.5){

System.out.println("Your BMI is UNDER WEIGHT. \nYou have to gain weight KG:" +uw);
} else if(BMI<25){
System.out.println("Congratulations. Your BMI is normal");
} else if(BMI<=30){

System.out.println("Your BMI is OVER WEIGHT. \nYou have to loose weight KG:" +ow);
} else{
System.out.println("Your BMI very high. It is OBESE.\nYou have to loose weight KG:" +ow);
}

}
}``````