Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af34f01

Browse files
Body Mass Index
1 parent 5435dc6 commit af34f01

File tree

3 files changed

+74
-18
lines changed

3 files changed

+74
-18
lines changed

‎Programming-Challenges/Decision-Structures/.idea/workspace.xml‎

Lines changed: 26 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /