## Problem:

Given an array of positive ints, return a new array of length "count" containing the first even numbers from the original array. The original array will contain at least "count" even numbers.

copyEvens({3, 2, 4, 5, 8}, 2) → {2, 4}
copyEvens({3, 2, 4, 5, 8}, 3) → {2, 4, 8}
copyEvens({6, 1, 2, 4, 5, 8}, 3) → {6, 2, 4}

## Solution:

public int[] copyEvens(int[] nums, int count) {
int ctr = 0;
int[] array = new int[count];
for (int i = 0; i < nums.length; i++) {
if (nums[i] % 2 == 0) {
array[ctr] = nums[i];
ctr++;
}
if (ctr == count)
return array;
}
return nums;
}

1. public int[] copyEvens(int[] nums, int count) {
int[] result = new int[count];
int counter = 0;
for(int i=0; i<nums.length && counter<count; i++)
{
if(nums[i]%2==0)
{
result[counter]=nums[i];
counter++;
}
}
return result;
}

2. int index=0;
int[] arr = new int[count];
for(int n : nums){
if(n%2==0 && index<count) {
arr[index]=n;
index++;
}
}return arr;

3. int[] filteredArray = Arrays.stream(nums).filter(n -> n%2==0).toArray();
return Arrays.copyOfRange(filteredArray, 0 ,count);