| 3 | //Problem : Calculate Diagonal Sum |
| 4 | |
| 5 | public class DiagonalSum { |
| 6 | public static int calcSum(int matrix[][]) { |
| 7 | int sum = 0; |
| 8 | //primary |
| 9 | for(int i=0, j=0; i<matrix.length; i++, j++) { |
| 10 | sum += matrix[i][j]; |
| 11 | } |
| 12 | |
| 13 | //secondary |
| 14 | for(int j=matrix.length-1, i=0; j>=0; j--,i++) { |
| 15 | if(i == j) { |
| 16 | continue; |
| 17 | } |
| 18 | sum += matrix[i][j]; |
| 19 | } |
| 20 | |
| 21 | return sum; |
| 22 | } |
| 23 | public static void main(String args[]) { |
| 24 | int matrix[][] = {{1, 2, 3, 4}, |
| 25 | {5, 6, 7, 8}, |
| 26 | {9, 10, 11, 12}, |
| 27 | {13, 14, 15, 16}}; |
| 28 | calcSum(matrix); |
| 29 | } |
| 30 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…