Answer to Question #212278 in Java | JSP | JSF for Sivasankar

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.


1
Expert's answer
2021-07-01T01:11:38-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS