+ 2
Stuck in Increment in Java!! (Shame on međ ) ... Write the output for the two cases
int x=2, y=2; Case 1:- x=x++; System.out.println (Wait...Loading....); System.out.println (Loading...); System.out.println (Finally loaded...); System.out.println ("x="+x+" y="+y); Case 2:- y=x=x++; System.out.println ("x="+x+" y="+y);
2 Answers
+ 3
In case 1, x is incremented by one, that is, x is now x = 3.
So output is
x=3y=2
Case 2,
First x++ is implemented, so, it will return 2 as its post increment. It will return value, then increment.
So, y = x = 2.
So, y and x is 2 now.
So output is,
x=2y=2
+ 3
Charitra Agarwal understood