# Arithmetic operator in java

I ran into unusual arithmetic operations and here is the code:

``````    int i = 9 + + 8 - - 11 + + 13 - - 14 + + 15;

System.out.println(i);
```

```

It works without compilation error and gives a result of 70, I tried googling but couldn't find the correct explanation. I'm sorry, I'm new to Java.

+3

source to share

``````int i = 9 + + 8 - - 11 + + 13 - - 14 + + 15;
```

```

equivalent to

``````int i = 9 + (+8) - (-11) + (+13) - (-14) + (+15);
```

```

which is equivalent

``````int i = 9 + 8 + 11 + 13 + 14 + 15;
```

```

equal to 70

+9

source

`9+ +8`

equivalent `9+(+8)`

and

`8- -11`

equivalent to `8-(-11)`

therefore `9 + + 8 - - 11 + + 13 - - 14 + + 15`

equivalent to`9+(+8)-(-11)+(+13)-(-14)+(+15)`

which is equivalent to `9+8+11+13+14+15`

=`70`

+2

source

It is actually a mathematical arithmetic operation, and the same applies to Java:

`- - = +`

`+ + = +`

`int i = 9 + 8 + 11 + 13 + 14 + 15;`

so what is it `70`

+2

source

All Articles