Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (pradius):

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?

OpenStudy (anonymous):

and is "&&"

OpenStudy (anonymous):

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

OpenStudy (pradius):

yeah but that operator is not working...

OpenStudy (anonymous):

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

OpenStudy (pradius):

u try it..

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (pradius):

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!

OpenStudy (rsmith6559):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Breathless: Spooky witch but cute
4 hours ago 3 Replies 0 Medals
Arriyanalol: help
4 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 3 Medals
Jaded012023: Please tell me what you all think of this song
7 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
6 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!