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
easy Solved by 1 students

2D Array Average Calculation

Mark
< Prev
Next >

What is the output of the following code segment?

public class Main {
    public static void main(String[] args) {
        int[][] matrix = { {2, 4}, {6, 8} };
        int total = 0, count = 0;
        for (int i = 0; i < matrix.length; i++){
            for (int j = 0; j < matrix[i].length; j++){
                total += matrix[i][j];
                count++;
            }
        }
        System.out.println(total / count);
    }
}
A

5.0

B

20/4

C

7

D

5

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|