multiple conditions in an "if" statement
807599Dec 5 2006 — edited Dec 5 2006Hi there,
I was just wondering if anyone could give me a quick answer on this one.
Say I have 2 acceptable conditions for entering an "if" block but one of the conditions has 2 conditions itself that need to be satisfied...will the code below work?
int z = 1;
int x = 4;
int y =5;
if ((x == 4 & y == 5) || z == 3) {
whatever;
}
In the above statement, obviously it can't go into the "if" block on the basis that z = 3, since z is equal to 1. However, I would like it to go in if x =4 and y = 5, which happens to be the case. My uncertainty is how java will read that if statement. If I don't have the brackets around x == 4 & y == 5, I don't know how it will interpret the statement. The way I see it, it could read it like this:
if (x == 4 & (y ==5 || z == 3)) {
whatever;
}
Anyways, if anyone understands what I'm trying to get at and what I'm trying to do, a little clarification would be appreciated. i.e. can you use brackets in "if" statements to group conditions?
Thanks,
jjmclell