Check if a number is even
How to solve it
%(although slightly different sometimes also referred to as Modulo operator).
The Remainder operator returns the remainder of an Integer division. For example:
10 % 3returns 1 because the number 3 fits no more than 3 times in 10. 3x3 is 9. Thus, the Remainder of
10 % 3is 10-9=1.
Now, how do we make use of the Remainder/Modulo operator to find out if a number is even oder odd? Well, we have to account for the fact that every even number is divisible by 2 while every odd number is not. So,
evenNumber % 2will always return zero.
oddNumber % 2will always return a number different from zero.