Answer the question
In order to leave comments, you need to log in
How does this expression work in java?
a=a+b-(b=a);
I know that this line swaps the values of the variables a and b, but how did the idea to do this even come about? Why is there a sum at all and why do we subtract the expression in brackets from it?
Answer the question
In order to leave comments, you need to log in
As you have already answered, here you need knowledge of the basics of arithmetic and logic. When it comes to programming, pay attention to operator precedence. For example, an expression enclosed in parentheses takes precedence, just like in mathematics.
2 * (2 + 2) = 8
2 * 2 + 2 = 6
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question