BMI Calculator Java Program [ 2024 ]
BMI Calculator Java Program
In this post, we will write a simple Java program called BMI Calculator to calculate a person’s BMI index. The program takes weight and height as input.
BMI Formula
BMI Index =
IDE Setup
We will use Eclipse IDE in this tutorial. Some steps and instructions to create a Java application on Eclipse IDE:
- Create Java Project in Eclipse
https://www.testingdocs.com/create-a-new-java-project-in-eclipse/
- Create Java Package in Eclipse
https://www.testingdocs.com/create-java-package-in-eclipse-ide/
- Create Java Class in Eclipse
https://www.testingdocs.com/create-a-new-java-class-in-a-project/
- Run Java Project in Eclipse
https://www.testingdocs.com/run-java-project-in-eclipse/
Java Program
/**************************************************
* BMICalculator.java
* @program :
* @web : www.TestingDocs.com
* @author :
* @version : 1.0
**************************************************/
import java.util.Scanner;
public class BMICalculator {
public static void main(String[] args) throws Exception {
System.out.print("Please enter weight in kg:= ");
Scanner keyboard = new Scanner(System.in);
double weight = keyboard.nextDouble();
System.out.print("Please enter height in meters:= ");
double height = keyboard.nextDouble();
double bmiIndex = calculateBMI(weight,height);
System.out.println("The BMI index is: "+ bmiIndex);
if(bmiIndex < 18.5) {
System.out.println("Underweight");
}else if (bmiIndex < 25) {
System.out.println("Normal");
}else if (bmiIndex < 30) {
System.out.println("Overweight");
}else {
System.out.println("Obese");
}
}
/**************************************************
* Method to calculate BMI Index
**************************************************/
private static double calculateBMI(double weight,double height) {
return (weight)/(height*height);
}
}
Sample Output
Please enter weight in kg:= 86
Please enter height in meters:= 1.77
The BMI index is: 27.450604870886398
Overweight
Screenshot

Rounding the Result
https://www.testingdocs.com/questions/how-to-round-a-double-value-in-java/
—
Java Tutorials
Java Tutorial on this website:
For more information on Java, visit the official website :