A good answer might be:

int x = ...... ;

if ( x % 2  ==  0 )

  System.out.println( x + " Is even " );
else
  System.out.println( x + " Is odd " );

Remainder with Negative Integers

The remainder operator can be used with negative integers. The rule is:

  1. Perform the operation as if both operands were positive.
  2. If the left operand is negative, then make the result negative.
  3. If the left operand is positive, then make the result positive.
  4. Ignore the sign of the right operand in all cases.

For example:

17 %  3 == 2     -17 %  3 == -2     
17 % -3 == 2     -17 % -3 == -2

You may wish to practice with the following:

Expression ResultExpression Result
7 -3 -7 5
-10 5 10 -6
-129 100 -1999 -100
-17 2 -18 2

QUESTION 14:

Does the value for pi ever change?