230k views
5 votes
an individual’s body mass index (bmi) is a measure of a person’s weight in relation to their height. it is calculated as follows: • divide a person’s weight (in kg) by the square of their height (in meters) design and implement a program to allow the user to enter their weight and height and then print out their bmi by using java

1 Answer

4 votes

Answer:

import java.util.*;

public class Main{

public static void main(String [] args){

double height, weight, bmi;

Scanner input = new Scanner(System.in);

System.out.print("Height (m): ");

height = input.nextDouble();

System.out.print("Weight (kg): ");

weight = input.nextDouble();

bmi =weight/(height * height);

System.out.print("BMI: "+bmi);

}

}

Step-by-step explanation:

This line declares height, weight and bmi as double

double height, weight, bmi;

This allows the program gets input from the user

Scanner input = new Scanner(System.in);

This prompts the user for height in meters

System.out.print("Height (m): ");

This gets an input for height

height = input.nextDouble();

This prompts the user for weight in kilogram

System.out.print("Weight (kg): ");

This gets an input for weight

weight = input.nextDouble();

This calculates bmi

bmi =weight/(height * height);

This prints the calculated bmi

System.out.print("BMI: "+bmi);

User Smugford
by
4.9k points