In Java, we have seven mathematical operators including:

**+**: plus**–**: subtraction*****: multiplication**/**: division**%**: modular division**++**: double plus**—**: double subtraction

It is easy for plus, subtraction, multiplication, division, and modular division, isn’t it? So, in this tutorial, I will focus only on two mathematical operators ++ and –.

The operators ++ and – are single operators that increase or decrease the value of a variable by a value of 1. These two operators may be before or after the variable name.

For example:

1 2 |
int a = 100; a++; |

Or

1 2 |
int b = 12; ++b; |

When these single operators are used in any expression, its position before or after the variable name determines whether the value of the variable associated with it increases or decreases before the expression is calculated. If this single operator is located before the variable name, the value of the variable will increase or decrease by 1 before the expression is calculated, or if it is after the variable name, the value of the variable will increase or decrease after the expression is calculated.

For example, we have an expression that uses the ++ operator as follows:

1 2 3 |
int a = 20; int b = 9; int c = b - ++a; |

In the expression int c = b- ++ a, the single ++ operator is located before the variable a, so the value of a in this expression will increase by 1 before the expression is computed. That is, we can rewrite the following:

1 |
int c = 9 - 21; |

The result would be -12. And after the expression ends, the value of a will be 21.

Similarly, let’s look at an example with the operator — as follows:

1 2 3 |
int a = 9; int b = 20; int c = b - a--; |

The result after running this expression is that c will be 11 and a will be 8.

Another classic example that we can look at is:

1 2 3 |
int a = 10; a = a-- + a + a++ - --a + a++; System.out.println(a); |

According to you, the results will look like?