Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Bad Operand for Binary Type Error (Can't figure this out)

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bad Operand for Binary Type Error (Can't figure this out)

    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?

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Bad Operand for Binary Type Error (Can't figure this out)

    Please paste your code between code tags (see BBCodes below). Check the tutorials in my signature on how to use if/else statements for comparison.

    https://docs.oracle.com/javase/tutor...bolts/op2.html

    Regards,
    Jim
    Last edited by jim829; January 27th, 2019 at 02:27 PM. Reason: update

Similar Threads

  1. Replies: 6
    Last Post: July 28th, 2014, 04:45 AM
  2. [SOLVED] Bad operand types for binary operator '<' error issue (beginner)
    By mju516 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 27th, 2012, 10:33 PM
  3. I can't figure out why i keep getting this error
    By chrissy2860 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 17th, 2011, 03:06 PM
  4. Solution for error message: Bad operand for binary operator '-'
    By MostinCredible21 in forum AWT / Java Swing
    Replies: 8
    Last Post: September 7th, 2011, 04:28 PM
  5. just one more error that i cannot figure out please help me.
    By knoxy5467 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: June 14th, 2011, 09:04 AM