Beginner Level
Implement the method isEven that takes an integer as input and returns true if the number is even, and false if it is odd.
You need to write a function that checks whether a given integer is even or not. A number is called even if it is divisible by 2 (e.g., 0, 2, 4, 6...). If it's not divisible by 2, it is odd (e.g., 1, 3, 5...). The method should return:
truefor even numbersfalsefor odd numbers
To check if a number is even:
-
Use the modulus operator
%to divide the number by 2. -
If the remainder is
0, the number is even. -
Otherwise, it’s odd.
Pseudocode:
Function isEven(n):
If n mod 2 equals 0:
Return true
Else:
Return false