class Output public static void mainString args int x y x
class Output { public static void main(String args[]) {
int x , y;
x = 10;
x++;
--x;
y = x++;
System.out.println(x + \" \" + y);
}
}
c) answer11 10
Why the answer is 11 10 not 10 11 the is not by going in order?
Solution
x = 10; //assigned value 10 to x
x++; //post-incrementation the value 10 become 11 in the next statement
--x;//pre-decrementaiton the value 11 becomes 10 here
y = x++//post-incrementation the value 10 is assigned to y and x becomes 11
Post-incrementation first the value of x is assinged to y then the value of x is incremented by one.So the output is
11 10
![class Output { public static void main(String args[]) { int x , y; x = 10; x++; --x; y = x++; System.out.println(x + \ class Output { public static void main(String args[]) { int x , y; x = 10; x++; --x; y = x++; System.out.println(x + \](/WebImages/24/class-output-public-static-void-mainstring-args-int-x-y-x-1062072-1761554981-0.webp)