Given the matrix shown and:
<code class="language-java">int sum = 0; for (int r = 0; r < m.length; r++) for (int c = 0; c < m[r].length; c++) if (r != c) sum += m[r][c]; </code></pre> What is the value of <code>sum</code>?
- A
33
- B
27
- C
45
- Dcheck_circle
31
Explanation
Sum of all entries = 2+4+6+1+3+5+7+8+9 = 45. The diagonal (r==c) values are 2, 3, 9 totaling 14. So 45 - 14 = 31.