Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Pradius

  • 4 years ago

Java Programming.. If I want to use the If statement to say : If (x > 4 and <9){} What operator should I use? or what method?

  • This Question is Closed
  1. jeffersonw
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    and is "&&"

  2. jeffersonw
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    so it would be If(x>4 && X<9){}

  3. Pradius
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah but that operator is not working...

  4. jeffersonw
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    && is the logical "and" operator to compare two boolean values, should be working

  5. Pradius
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    u try it..

  6. 1ncident
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    try putting it in parentheses so if ((x>4)&&(x<9))

  7. fr33
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    if(( x > 4) && (X < 9 )) { //Do something here. } Hey! That's exactly I was going to post lol

  8. Pradius
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There you go , That's exactly what I was looking for.. I was trying something like that but without some parenthesis If (x >4)&(<9) but I forgot that theres only one condition so everything must be within a set of parenthesis. Thanks man!

  9. rsmith6559
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Just so you know, the single ampersand is a legal operator. It's used for bitwise and.

  10. tuhinrawat90
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    if(x>4 && x<9 ) { // your stuff }

  11. Creperum
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There's also the assignment conditional operator used for singular assignments. a = (b > c) ? b : c; So if b is greater than c, a takes the value of b, otherwise it takes the value of c. More formally, this is read as: value = (condition) ? (true value) : (false value); The condition can be any valid conditional statement, as long as it validates before the ? operator.

  12. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy