Here's my code, basically a small program to calculate Body Mass Index. For some reason I get the follow error below the code.
import java.util.Scanner;
public class BMI{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double BMI;
double weight;
double height1;
double height2;
// was using these, but not atm
/* double overweightValue = 25;
double underweightValue = 18.5; */
System.out.println("What is your weight? ");
weight = input.nextDouble();
System.out.println("What is your height? ");
height1 = input.nextDouble();
height2 = (height1 * 12);
BMI = (weight * 703) / (height2 * height2);
if (BMI > 25){
System.out.println("Your BMI is in the overweight range! ");
}
if (25 > BMI > 18.5) {
System.out.println("Your BMI is in the optimal range! ");
}
if (BMI < 18.5) {
System.out.println("Your BMI is in the underweight range! ");
}
}
}
C:\Users\jamea\Desktop\Java Programs\BMI.java:31: error: bad operand types for binary operator '>'
if (25 > BMI > 18.5) {
^
first type: boolean
second type: double
1 error
Tool completed with exit code 1
It's pretty clear that I cannot use the "<" and ">" operators in an if statement. But how else would I achieve this?