Search This Blog

Showing posts with label java calculator. Show all posts
Showing posts with label java calculator. Show all posts

Body Mass Index Calculator Using Java - Java Application Code

Body Mass Index Calculation is based on your weight and height. Body Mass Index (BMI) = weight/(height*height) where weight is in kilograms and height in meters. The following Java program takes weight and height as input and displays BMI and grades into underweight,Normal, Overweight or obesity.


import java.util.Scanner;

public class BMI {

public static void main(String[] arg)
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter weight in kgs and height in meters");
    float bmi=sc.nextFloat()/(float)Math.pow(sc.nextFloat(),2);
    String s=(bmi<18.5)?"Underweight":(bmi<25)?"Normal weight":(bmi<30)?"Overweight":"Obesity";
    System.out.println("bmi: "+bmi+"   "+s);
    }
}

Calculate your BMI here

Weight (in kg):
Height (in meters):