005-002-012

If-Else: BMI Calculator

Hard

Problem Description

If-Else: BMI Calculator

In this problem, you will create a program that reads height and weight from standard input, calculates a BMI value, classifies the result into one of four categories using if-else statements, and displays the result to standard output.

Learning Objective: Use calculated results in conditional checks for classification

Overview

Create a program that reads height and weight as input, calculates BMI, then outputs the assessment.

Input

height (meters, double)
weight (kilograms, double)

Specifications

  • Read height (meters) into variable height using Scanner
  • Read weight (kilograms) into variable weight using Scanner
  • Calculate BMI (BMI = weight / height squared)
  • Assess based on:
    • BMI below 18.5: "Underweight"
    • BMI 18.5 to under 25: "Normal"
    • BMI 25 to under 30: "Overweight"
    • BMI 30 or above: "Obese"
  • Output BMI value and assessment

Output Format

BMI: 22.49
Category: Normal

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up