String BMICategory;
if (bodyMassIndex < 18.5)
{
BMICategory = "underweight";
}
else if (bodyMassIndex >= 18.5 && bodyMassIndex <= 25)
{
BMICategory = "optimal weight";
}
else
{
BMICategory = "overweight";
}
Then, put something in the output like:
System.out.println("Your BMI is: " + bodyMassIndex + ". You are " + BMICategory + ".");
This should give you something like "Your BMI is 20. You are optimal weight."
You would use an if, else if, and else statement
//
if (bodyMassIndex > 18.5 || bodyMassIndex < 25)
{
System.out.print("optimal")
}
else if(bodyMassIndex < 18){
System.out.print("underweight")
}
else
system.out.print("over weight")
You dont to check the weight on the last one because if it isnt optimal and if it isnt underwieght then its overweight
Here's what I have so far, cant figure out how to display a message indicating whether the person had optimal weight(between 18.5 and 25), underweight(less than 18.5) or overweight(over 25).
Note: I'm in a hybrid Intro to Programming 101 class with only a hour of instruction a week.
We use JGrasp and Java.
Than you!!
import java.util.Scanner;
// BMI calculator
public class BodyMassIndex
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner ( System.in );
final double BMI_CONVERSION = 703.0; // pounds/inches to kilograms/meters for BMI calculations
double bodyMassIndex;
double height;
double weight;
// input
System.out.print( "What's your height in inches? ");
height = keyboard.nextDouble();
System.out.print( "What's you weight in pounds? ");
weight = keyboard.nextDouble();
// Calculate BMI
bodyMassIndex = weight * BMI_CONVERSION / (height * height);
// output
System.out.println( "Your BMI is: " + bodyMassIndex );
}
}