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 Sum of a 2D Array

Mark
< Prev
Next >

What value is printed as a result of executing the following code?

public class RecursiveSum {
    public static int recursiveSum(int[][] arr, int r, int c) {
        if(r >= arr.length) return 0;
        if(c >= arr[r].length) return recursiveSum(arr, r+1, 0);
        return arr[r][c] + recursiveSum(arr, r, c+1);
    }
    public static void main(String[] args) {
        int[][] data = { {1,2}, {3,4} };
        System.out.print(recursiveSum(data, 0, 0));
    }
}
A

11

B

9

C

8

D

10

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|