Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
hard Solved by 1 students

Recursive 2D Array Traversal

Mark
< Prev
Next >

What is the output produced by the following program?

public class EvenSum {
    public static int sumEven(int[][] arr, int i, int j) {
        if (i == arr.length) return 0;
        if (j == arr[i].length) return sumEven(arr, i + 1, 0);
        int add = (arr[i][j] % 2 == 0) ? arr[i][j] : 0;
        return add + sumEven(arr, i, j + 1);
    }
    public static void main(String[] args) {
        int[][] matrix = { {1, 2, 3}, {4, 5, 6} };
        System.out.println(sumEven(matrix, 0, 0));
    }
}
A

6

B

12

C

10

D

14

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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|