2D Array Average Calculation
What is the output of the program when executed?
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
7
B
5
C
20/4
D
5.0
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE