countEvens([2, 1, 2, 3, 4]) → 3
countEvens([2, 2, 0]) → 3
countEvens([1, 3, 5]) → 0
Answer 1:
public int countEvens(int[] nums) {
int evenCount = 0;
for(int i=0;i<nums.length;i++){
if(nums[i]%2==0) evenCount++;
}
return evenCount;
}
public int countEvens(int[] nums) {
int evenCount = 0;
for(int i=0;i<nums.length;i++){
if(nums[i]%2==0) evenCount++;
}
return evenCount;
}
No comments :
Post a Comment