What does each expression evaluate to? Assume x is 2 before each one.
-
int num = x++ * 3;
So this would be equivalent to (2)*3 or num=6 and x is now 3. -
num *= x;
num =2*2 or 4 -
(x < 2) && (x > 1)
Becomes FALSE, because (2<2)=false and (2>1)=true so it’s false. -
(++x < 2) || (x < 1)
(3<2)is false and then((2+1)<1)is also false, so it’s false?
One question is in this case, is the preincrement applied to the variable before the break? Should the second x value be 3 or 2?
I also have the same question for postincrement. Let’s say I havenum=x++ *x++where initial x=2. So is this 2*2 or 2*3?
It’s incremented before the “break” yes. Basically it’s the first thing java does (parenthesis are still the first ones actually). So in (++x < 2) || (++x < 3) the 2nd ++x happens after the first one if it isn’t true.