Arithmetic operators in Java
•
Java
I encountered a strange arithmetic operation. Here is the code:
int i = 9 + + 8 - - 11 + + 13 - - 14 + + 15; System.out.println(i);
It works without compilation errors and gives output 70. I tried Google but couldn't find the correct explanation Please forgive me, I'm a novice in Java
Solution
int i = 9 + + 8 - - 11 + + 13 - - 14 + + 15;
int i = 9 + + 8 - - 11 + + 13 - - 14 + + 15;
amount to
int i = 9 + (+8) - (-11) + (+13) - (-14) + (+15);
This is equivalent to
int i = 9 + 8 + 11 + 13 + 14 + 15;
Equal to 70
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码