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 IntegersThe 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: |
QUESTION 14:Does the value for pi ever change? Click Here after you have answered the question |