Home > Mobile >  error: bad operand types for binary operator '>=' "else if (bmi <=18.5 >=25.
error: bad operand types for binary operator '>=' "else if (bmi <=18.5 >=25.

Time:10-17

error: bad operand types for binary operator '>=' "else if (bmi <=18.5 >=25.0)"
how to solve this?

    int bmi;
    
    Scanner console = new Scanner(System.in);
    
    System.out.print("Measure your height and weight.")
    Systen.out.print("Then Calculate your BMI.")
    System.out,print("Enter how many score you got : ")
    bmi = console.nextINt();
    
    if (bmi <= 18.4)
    {
        System.out.println("You're under weight, you need to gain more weight!");
    }
    else if (bmi <=18.5 >=24.9)
    {
        System.out.println("You're normal, Congrats!");
    }
    else if (bmi <=25.0)
    {
        System.out.println("You're Overweight, you need to lose some weight.");
    }

CodePudding user response:

    int bmi;

Scanner console = new Scanner(System.in);

System.out.print("Measure your height and weight.")
Systen.out.print("Then Calculate your BMI.")
System.out,print("Enter how many score you got : ")
bmi = console.nextINt();

if (bmi <= 18.4)
{
    System.out.println("You're under weight, you need to gain more weight!");
}
else if (bmi < 25)
{
    System.out.println("You're normal, Congrats!");
}
else 
{
    System.out.println("You're Overweight, you need to lose some weight.");
}

CodePudding user response:

is it same as this and still showing error?
Also, why take bmi as int, why not float as you are comparing it with float values.
replace console.nextInt() to console.nextFloat() for accepting float input

float bmi = console.nextFloat();
if (bmi <= 18.4)
{
    System.out.println("You're under weight, you need to gain more weight!");
}
else if (bmi >=18.5 && bmi <=24.9)
{
    System.out.println("You're normal, Congrats!");
}
else if (bmi >=25.0)
{
    System.out.println("You're Overweight, you need to lose some weight.");
}
  •  Tags:  
  • java
  • Related