FastPrepFastPrep
Problem Brief

Count Even Numbers

OA

Given an integer array nums, return the number of elements that are even.

An integer is even if it is divisible by 2. If nums is empty, return 0.

1Example 1

Input
nums = [1,2,4,7,10]
Output
3
Explanation
The even numbers are 2, 4, and 10.

2Example 2

Input
nums = []
Output
0
Explanation
The array is empty.

3Example 3

Input
nums = [-3,-2,0,5,8]
Output
3
Explanation
The even numbers are -2, 0, and 8.

Constraints

Limits and guarantees your solution can rely on.

  • 0 <= nums.length <= 1000
  • -100000 <= nums[i] <= 100000
public int countEvenNumbers(int[] nums) {
  // write your code here
}
Input

nums

[1,2,4,7,10]

Output

3

Sign in to submit your solution.