MCPcopy Create free account
hub / github.com/apna-college/Alpha / DiagonalSum

Class DiagonalSum

4_2DArrays/DiagonalSum.java:5–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3//Problem : Calculate Diagonal Sum
4
5public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…