有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java错误:二进制运算符“>=”的操作数类型不正确,否则如果(bmi<=18.5>=25.0)

错误:二进制运算符“>;=”的操作数类型错误“如果体重指数(bmi<;=18.5>;=25.0)出现其他情况,”
如何解决这个问题

    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.");
    }

共 (2) 个答案

  1. # 1 楼答案

        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.");
    }
    
  2. # 2 楼答案

    是否与此相同,但仍显示错误
    另外,为什么将bmi作为int,为什么不将float作为与浮点值的比较呢
    console.nextInt()替换为console.nextFloat()以接受浮点输入

    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.");
    }