KnowledgeBoat Logo
|

Computer Applications

What will be the output of the following code?

int x = 9;
x -= 2 * --x / x++ % 3;
System.out.println("x = " + x);

Java Operators

2 Likes

Answer

x = 7

Reason — The given expression is evaluated as follows:

Initial value: x = 9

x -= 2 * --x / x++ % 3
x = x - (2 * --x / x++ % 3) [x=9]
x = 9 - (2 * 8 / 8 % 3) [x=9]
x = 9 - (16 / 8 % 3)
x = 9 - (2 % 3)
x = 9 - 2
x = 7

Answered By

2 Likes


Related Questions