Example


\begin{lstlisting}
class UnaryOperator {
public static void main(String[] args)...
...System.out.println(++number);
System.out.println(number);
}
}
\end{lstlisting}

The output for the above code will be as below


\begin{lstlisting}
5.2
6.2
7.2
7.2
\end{lstlisting}

Here, notice the line, $\lstinline{System.out.println(number++);}$; When this statement is executed, the original value is evaluated first. Then the number is increased. This is the reason you are getting 5.2 as an output. Now, when the line, $\lstinline{System.out.println(number);}$ will print the increased value. That is 6.2. However, the line, $\texttt{System.out.println(++number);}$ will increase the number by 1 first and then the statement is executed. Hence the output is 7.2. Similar is the case for decrement – operator.