Give output of the following Java program:
Int k=5; j=9;
k+=k++-++j+k;
Sopln(k+""+j);
Answers
Answer:
The ans is 6
Explanation:
we can simply the syntax to help us understand.
int k = 5, j = 9;
k = k + ((k++)-(++j)+k);
Sopln(k+""+j);
.
.
x++ = interpreter will execute the statement first and then increment the variable
++x = interpreter will increment the variable, and then execute the statement with the new values...
k = 5, j = 9
1. (k++)
2. -(++j)
3. +k
1. k is still 5, its value is passed on and then incremented to 6
5 + -(++j)+k
2. j is incremented and the value is passed on
5 - 10 + k
3. k is 6 (changed in step 1), and the value is passed on...
5 - 10 + 6
-5 + 6
1
now we see the whole thing was being added to the old value of k(old value is 5)
k = k + 1
k = 5 + 1
Therefore k is now 6
I hope you understood, English is not my primary language
Answer:
answer is 6...
..........................