Question #212278

Write a function:

class Solution { public int solution (int[] A); }

that, given an array A consisting of N integers, returns the sum of all integers which are multiples of 4.


Expert's answer

class Solution {
    public int solution(int[] A) {
        int total = 0;
        for (int a : A) {
            if (a % 4 == 0) {
                total += a;
            }
        }
        return total;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS