Increment/ Decrement Operator in Java

The increment operator (++) adds one to the value of a variable

For example :
if n is equal to 2, then n++ or ++n will change the value of n to 3.

The decrement operator (–) subtracts one from the value of a variable.

For example:
If n is equal to 4, then n– or –n will change the value of n to 3.

When either operator precedes its variable and is a part of an expression then the expression is evaluated using the changed
value of the variable.

For example :
If n is equal to 6, then 2*(++n) evaluates to 14.

When either operator follows its variable, and is a part of an expression then the expression is evaluated using the original
value of the variable, and only then is the variable value changed

For example :
If n is equal to 6, then 2*(n++) evaluates to 12.

However, in both cases given above the value of n will finally be 7.

You can find the code here

Rutu Shah