2D Array Average Calculation
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
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE