Computer Applications
If x = 5
and y = 4
, what will be the output of the following code?
x += ++y - x-- + y++;
System.out.println("x = " + x);
System.out.println("y = " + y);
Java Operators
2 Likes
Answer
x = 10
y = 6
Reason — The given expression is evaluated as follows:
x += ++y - x-- + y++
x = x + (++y - x-- + y++) [x=5, y=4]
x = 5 + (5 - 5 + 5) [x=4, y=6]
x = 5 + 5
x = 10
and
y=6
Answered By
3 Likes