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 3 of 3

Thread: If statement problems

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    14
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default If statement problems

    I'm only like two days into my first Java...well first programming class ever and here's my issue, or the issue I created for myself rather.

    For starters it's a basic BMI program. I have the basics down, pretty simple. At the end of the program after all input has been made and a BMI determined I want it to print results like: Your BMI is less than 18.5, you are underweight...which is fine, I can do that. However Theres a range for normal and overweight, ranges 18.5 - 24.9 and 25 - 29.9 for overweight. How would I create the relational operator on a range of values such as these to print the proper result?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: If statement problems

    Combine the operators. See Equality, Relational, and Conditional Operators . If you get stuck along the way I'd recommend posting code with a defined question to get a quicker and more precise response.

  3. #3
    Member
    Join Date
    Dec 2010
    Posts
    46
    Thanks
    0
    Thanked 10 Times in 10 Posts

    Default Re: If statement problems

    Quote Originally Posted by SnarkKnuckle View Post
    However Theres a range for normal and overweight, ranges 18.5 - 24.9 and 25 - 29.9 for overweight. How would I create the relational operator on a range of values such as these to print the proper result?
    here's an example for you
    if ( myVariable >= 20 && myVariable <=30 ){
        System.out.println("you failed" );
    }else if ( .......... ){
         ...........
    }

  4. The Following User Says Thank You to JavaHater For This Useful Post:

    SnarkKnuckle (January 24th, 2011)

Similar Threads

  1. If Statement
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 26th, 2010, 12:57 PM
  2. Nested If Else Statement
    By jwill22 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 6th, 2010, 02:46 PM
  3. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 07:57 PM
  4. unreachable statement Again?
    By chronoz13 in forum Loops & Control Statements
    Replies: 3
    Last Post: October 1st, 2009, 10:23 AM
  5. If statement
    By Dave in forum Loops & Control Statements
    Replies: 2
    Last Post: August 27th, 2009, 10:11 AM