Originally Posted by
vivjo
& is Bitwise And Operator
Use && and it would work
if(a>b && a>c)
The code is working fine
Hmm, that should still work. Using a single & (or |) instead of the double && or || will simply cause both statements to be evaluated instead of shortcutting. With double &&, if the left side is false, it doesn't bother testing the right side. Same with double ||, only with true instead of false.
With a single & or |, it tests both sides no matter what. Try out different values for t with both & and && in this program:
public class Test{
public static void main(String... args)
{
int x = 9;
boolean test = testVariable(x, 4) & testVariable(x, 5);
System.out.println(test);
}
public static boolean testVariable(int x, int t){
System.out.println("Testing: " + x + " < " + t + ": " + (x < t) );
return x < t;
}
}