| 2:51 pm on Oct 2, 2001 (gmt 0)|
x += y means add y to x and put the result back into x
x < y ? y : x means
if x < y then
x++ means add 1 to x and put the result back into x, but only after doing the rest of the operation that x is involved in
| 4:26 pm on Oct 2, 2001 (gmt 0)|
The result is supposed to be one of these:
a) 4 3 2 1
b) 3 2 3 3
c) 3 3 3 3
Y'know, statistically speaking, I've heard that you'll tend to get the best scores on multiple-choice exams by sticking with your first gut-instinct answer. ;)
| 5:49 pm on Oct 2, 2001 (gmt 0)|
I remember hearing that on multiple choice it was always safe to go with "C".........so:
c) 3 3 3 3 hehe :)
| 6:58 pm on Oct 2, 2001 (gmt 0)|
You'll get an error with this because "z" is not declared... "Z" is declared but not used. So...
x += y += z;
System.out.println(x < y ? y : x);
System.out.println(x < y ? x++ : 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...
The answer is B.
| 7:00 pm on Oct 2, 2001 (gmt 0)|
BTW, Xoc gave a very good description of how the operators work.
| 11:40 pm on Oct 2, 2001 (gmt 0)|
Sure sounds to me that you are doing someone's homework for them.
| 8:33 am on Oct 3, 2001 (gmt 0)|
thanx very much for your help. It is indeed part of my homework but I'm doing a correspondence course and my teacher is not very helpful, if ever he replies to a question.