Forum Moderators: open
int x,y,z;
x = 1; y = 1, Z = 1;
x += y += z;
System.out.println(x < y ? y : x);
System.out.println(x < y ? x ++ : y ++);
System.out.println(x);
System.out.println(y);
The result is supposed to be one of these:
a) 4 3 2 1
b) 3 2 3 3
c) 3 3 3 3
Any tips welcome. Thank You!!!
Mat*
int x=1,y=1,z=1;
x += y += z;
System.out.println(x < y ? y : x);
System.out.println(x < y ? x++ : y++);
System.out.println(x);
System.out.println(y);
Be careful with this: x += y += z;
What you really have is this: x += (y += z);
And that's ok if that's what you want.
Solve it from the inside out...
z is 1
y becomes 2
x becomes 3
Now the output statements...
x is not < y, so print x, which is 3
x is not < y, so print y, which is 2,
then increment y by 1, and y becomes 3
print x, which is 3
print y, which is 3
The result is...
3
2
3
3
The answer is B.