user2381832
user2381832

Reputation: 146

How does mentioning multiple arithmetic operation within two operands work in Java

I have an expression in my code -
int i = 10 + + 11 - - 12 + + 13 - - 14 + + 15;
The value of the variable 'i' evaluates to 75, which is the sum of all the integers mentioned in the expression. How does the evaluation happen in this scenario?

Upvotes: 6

Views: 140

Answers (2)

Sachin Chandil
Sachin Chandil

Reputation: 17829

First all unary operator will be evaluated. Ex: - - 10 = +10.

Rest you can evaluate now.

Upvotes: 0

Madhawa Priyashantha
Madhawa Priyashantha

Reputation: 9900

this evaluate as

int i = 10 + (+ 11) - (- 12) + (+ 13) - (- 14) + (+ 15);

evaluate to

int i= 10 +11+12+13+14+15;

and all become + so value is 75.note - -is +

Upvotes: 10

Related Questions