w3resource
Java Programming Exercies

Java Data Type Exercises: Compute body mass index (BMI)

Java Data Type: Exercise-6 with Solution

Write a Java program to compute body mass index (BMI).

BMI: The BMI is defined as the body mass divided by the square of the body height, and is universally expressed in units of kg/m2, resulting from mass in kilograms and height in metres.

Test Data
Input weight in pounds: 452
Input height in inches: 72

Java datatype Exercises: Compute body mass index (BMI)

Sample Solution:

Java Code:

import java.util.Scanner;
public class Exercise6 {

    public static void main(String[] Strings) {

        Scanner input = new Scanner(System.in);

        System.out.print("Input weight in pounds: ");
        double weight = input.nextDouble();

        System.out.print("Input height in inches: ");
        double inches = input.nextDouble();

        double BMI = weight * 0.45359237 / (inches * 0.0254 * inches * 0.0254);
        System.out.print("Body Mass Index is " + BMI+"\n");
    }
}

Sample Output:

Input weight in pounds: 452                                                                                   
Input height in inches: 72                                                                                    
Body Mass Index is 61.30159143458721

Flowchart:

Flowchart: Java Data Type Exercises - Compute body mass index (BMI)

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Print the current time in GMT
Next: Write a Java program to display the speed, in meters per second, kilometers per hour and miles per hour.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming


bedava porno