int x = ...... ; if ( x % 2 == 0 ) System.out.println( x + " Is even " ); else System.out.println( x + " Is odd " );
The remainder operator can be used with negative integers. The rule is:
For example:
17 % 3 == 2 -17 % 3 == -2 17 % -3 == 2 -17 % -3 == -2
You may wish to practice with the following: