how to use greater than and less than in a single if statement in java

后端 未结 2 832
庸人自扰
庸人自扰 2021-01-22 17:04

I have made a BMI calculator from programming by doing, one of the thing i have to do is add categories using if statements. 18.5 to 24.9 normal weight so that would be one of t

相关标签:
2条回答
  • 2021-01-22 17:47

    Use

    if ( bmi > 18.5 && bmi < 24.9)
    

    Unfortunately, Java does not support a 'BETWEEN' operator (like what SQL does e.g).

    0 讨论(0)
  • 2021-01-22 18:08

    You could write your own method to check if between,

    public static boolean isBetween(int low, int high, int vmi) {
        return high > low ? bmi > low && bmi < high : bmi > high && bmi < low;
    }
    
    0 讨论(0)
提交回复
热议问题