Skip to content

Commit 781c66c

Browse files
authored
Create Average Value of Even Numbers That Are Divisible by Three.java
1 parent 3054444 commit 781c66c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int averageValue(int[] nums) {
3+
int total = 0;
4+
int count = 0;
5+
for (int num : nums) {
6+
if (num % 2 == 0 && num % 3 == 0) {
7+
total += num;
8+
count++;
9+
}
10+
}
11+
return count == 0 ? 0 : total / count;
12+
}
13+
}

0 commit comments

Comments
 (0)