Loading...
Loading...
A fitness app works out the Body Mass Index: BMI = weight in kg ÷ (height in metres)². The categories are:
UnderweightNormalOverweightObeseRead the weight in kg and the height in centimetres, and print the BMI with two decimal places and the category.
BMI: X.XX and the category.Example 1
Input
70 175
Output
BMI: 22.86 Normal
70 ÷ 1.75² = 22.857…, which is Normal.
Example 2
Input
64 160
Output
BMI: 25.00 Overweight
64 ÷ 1.6² is exactly 25.00, so it is already Overweight.
Try the problem first. Open one hint at a time.
Convert centimetres to metres by dividing by 100, or use BMI = weight × 10000 ÷ height², which avoids decimals until the last step.
Make sure the division is done in double, not int.
Each category has a lower bound that is included, so test bmi < 18.5, then bmi < 25, then bmi < 30.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor