| 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
< 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

7

C

5

D

20/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: apfive@apfive.org|Privacy Policy