Given an array of ints, return the number of 9's in the array.
arrayCount9([1, 2, 9]) → 1 arrayCount9([1, 9, 9]) → 2 arrayCount9([1, 9, 9, 3, 9]) → 3 |
Hisoka :
1 2 3 4 5 6 7 8 9 | public int arrayCount9(int[] nums) { int count = 0; for( int a : nums) { if(a == 9) count++; } return count; } |
Codingbat :
1 2 3 4 5 6 7 8 9 | public int arrayCount9(int[] nums) { int count = 0; for (int i=0; i<nums.length; i++) { if (nums[i] == 9) { count++; } } return count; } |
No comments:
Post a Comment