| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
easy Solved by 1 students
Conditional Sum Of 2D Array Elements
< Prev
Next >

What is printed by the above code?

public class Sum2D {
    public static void main(String[] args) {
        int[][] grid = { {2, 3}, {4, 5} };
        int sum = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                if (grid[i][j] % 2 == 0)
                    sum += grid[i][j];
            }
        }
        System.out.println(sum);
    }
}
A

2

B

9

C

6

D

4

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy