|
| 1 | +/* |
| 2 | +Write a program that calculates and displays a person’s body mass index (BMI). |
| 3 | +The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. |
| 4 | +A person’s BMI is calculated with the following formula: |
| 5 | +
|
| 6 | +BMI = Weight x 703 / Height (squared) |
| 7 | +
|
| 8 | +where weight is measured in pounds and height is measured in inches. |
| 9 | +
|
| 10 | +The program should display a message indicating whether the person has optimal weight, is underweight, or is overweight. |
| 11 | +A sedentary person’s weight is considered optimal if his or her BMI is between 18.5 and 25. |
| 12 | +If the BMI is less than 18.5, the person is considered underweight. |
| 13 | +If the BMI value is greater than 25, the person is considered overweight. |
| 14 | + */ |
| 15 | + |
| 16 | +package com.challenges; |
| 17 | + |
| 18 | +import java.util.Scanner; |
| 19 | + |
| 20 | +public class BodyMassIndex { |
| 21 | + public static void main(String [] args) { |
| 22 | + |
| 23 | + // Declare Variables |
| 24 | + double weight; |
| 25 | + double height; |
| 26 | + double BMI; // BMI = Weight x 703 / Height (squared) |
| 27 | + |
| 28 | + Scanner scanner = new Scanner(System.in); |
| 29 | + |
| 30 | + System.out.println("Please enter your weight in pounds: "); |
| 31 | + weight = scanner.nextDouble(); |
| 32 | + |
| 33 | + System.out.println("Please enter your height inches: "); |
| 34 | + height = scanner.nextDouble(); |
| 35 | + |
| 36 | + BMI = weight * (703 / (height * height)); |
| 37 | + |
| 38 | + if(BMI < 18.5) { |
| 39 | + System.out.println("You are underweight! Your BMI is " + BMI + "."); |
| 40 | + } |
| 41 | + else if(BMI > 25){ |
| 42 | + System.out.println("You are overweight! Your BMI is " + BMI + "."); |
| 43 | + } |
| 44 | + else { |
| 45 | + System.out.println("Your weight is optimal for your height. Your BMI is " + BMI + "."); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments