In: Computer Science
Design a modular program that calculates and displays a person's body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. A person's BMI is calculated with the following formula: BMI=Weight*703/Height^2. I need help making this to Java to just calculate BMI.
CODE FOR THE FOLLOWING PROGRAM:-
import java.util.Scanner; // Import the Scanner class
import java.lang.Math; // import math class for pow() function
public class Main
{
//function to calculate bmi
static double CalculateBMI(double height,double weight) {
double BMI=(weight*703)/Math.pow(height, 2);
return BMI;
}
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
double height,weight;
System.out.println("Enter height in inches:");
height = myObj.nextDouble(); // Read height entered by user
System.out.println("Enter weight in kgs:");
weight = myObj.nextDouble(); // Read weight entered by user
double bmi=CalculateBMI(height,weight);
System.out.println("The BMI of the person is: "+bmi);
}
}
SCREENSHOT OF THE PROGRAM AND SAMPLE OUTPUT:-
SAMPLE OUTPUT:-
HAPPY LEARNING