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

Thread: If stament

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default If stament

    if(experience <= num3) {
    System.out.println("You are a JAVA developer");
    if(num3 > experience <= num2) {
    System.out.println("You are a JAVA Senior");
    if(num1 > experience <= num1) {
    System.out.println("You are a JAVA Analyst");
    }else{
    System.out.println("You are a JAVA Consultant");


    Can someone tell me what is wrong with my code !?
    It says that this bit of code is wrong. >>>> if(num3 > experience <= num2)
    I would appreciate any help.
    Thank you.
    Have a good sunday.
    Bye

  2. Default Related threads:


  3. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: If stament

    The compiler wants binary operators like <, <=, > etc to have an operand on each side. Your expression violates the rules.
    Try putting a pair of () around each subexpression: (operand operator operand). For example:
    (a > b) && (a < d)
    Each subexpression evaluates to a boolean value: (A > 1) is true or false. The subexpressions must be connected with a boolean operator like AND, NOT and OR to make another boolean expression.
    if statements require a boolean expression inside of the ()s
    if(boolean expression) ....

  4. #3
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: If stament

    Java must have a bracket at both ends of the if statement. IE if (a > b)&&(a<b) {"Value";}

    just stating as you have 4 open brackets and only 1 closing bracket
    for every open there must be a close.


    Credit to norm for the expression.
    Last edited by lorider93p; February 7th, 2012 at 11:13 AM. Reason: expresion in reason

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: If stament

    The ifs could be nested:

    if(experience <= num3) {
       System.out.println("You are a JAVA developer");
       if(num3 > experience <= num2) {
          System.out.println("You are a JAVA Senior");
          if(num1 > experience <= num1) {
             System.out.println("You are a JAVA Analyst");
          }else{
             System.out.println("You are a JAVA Consultant");
          }  // These three } were missing in the original
       }
    }

  6. #5
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: If stament

    that is a good point. but still need the three }s or u will get errors. SO that goes down to do u want to say you are all of the above you qwualify or just the highest. and this is just a logic on my part i might not be understanding the code but you might be with the
     if(num1 > experience <= num1)
    why dont you just place it so experience is equal to num1
     if (num1 == experience)
    or is that a error becuase your saying if num1 is less than experience and experience is greater than or equal to num1 (logical error) because it is impossible to be less than but still greater than or equal to. just a thought.

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: If stament

    The OP will have to say what the code is supposed to do.

  8. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: If stament

    Quote Originally Posted by Norm View Post
    The ifs could be nested:

    if(experience <= num3) {
       System.out.println("You are a JAVA developer");
       if(num3 > experience <= num2) {
          System.out.println("You are a JAVA Senior");
          if(num1 > experience <= num1) {
             System.out.println("You are a JAVA Analyst");
          }else{
             System.out.println("You are a JAVA Consultant");
          }  // These three } were missing in the original
       }
    }
    in this case first you are saying if experience is lower than num 3 than if true, if experience num3 greater than experience

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: If stament

    Again, you will have to ask the OP what the code is supposed to do.