Implement the method isEven that takes an integer as input and returns true if the number is even, and false if it is odd.

Beginner Level
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:
  • true for even numbers
  • false for odd numbers
Example 1
Input:
n (int) = 4
Return:
(boolean) true
Example 2
Input:
n (int) = 7
Return:
(boolean) false
Example 3
Input:
n (int) = 0
Return:
(boolean) true
Example 4
Input:
n (int) = -2
Return:
(boolean) true
Example 5
Input:
n (int) = -3
Return:
(boolean) false

To check if a number is even:

  1. Use the modulus operator % to divide the number by 2.

  2. If the remainder is 0, the number is even.

  3. Otherwise, it’s odd.

Pseudocode:

Function isEven(n):
    If n mod 2 equals 0:
        Return true
    Else:
        Return false
Run your code to see the result.