Find the product of sum of two diagonals of a square Matrix | Java program to find the product of the sum of diagonals . ; Function to find the product of the sum of diagonals . ; Initialize sums of diagonals ; Return the answer ; Driven code ; Function call
class GFG { static long product ( int [ ] [ ] mat , int n ) { long d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return 1L * d1 * d2 ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 5 , 8 , 1 } , { 5 , 10 , 3 } , { - 6 , 17 , - 9 } } ; int n = mat . length ; System . out . print ( product ( mat , n ) ) ; } }