Beginner Level

Implement the method countEvenNumbers that returns how many even numbers are in an array.

Count how many even integers appear in an array. An even number is divisible by 2 with no remainder.

The task is designed to test careful handling of edge cases, not only the most common input.

  • Use only the first size elements.
  • Zero should be counted as even.
  • The array may contain positive and negative values.

Example 1

Input
nums (int[]) = [1, 2, 3, 4, 5]
size (int) = 5
Returns (int) 2

Example 2

Input
nums (int[]) = [2, 4, 6]
size (int) = 3
Returns (int) 3

Example 3

Input
nums (int[]) = [1, 3, 5]
size (int) = 3
Returns (int) 0

Example 4

Input
nums (int[]) = [-2, -1, 0, 7]
size (int) = 4
Returns (int) 2

Loop through the requested range and increase the answer whenever value % 2 == 0.

Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.