Sum of both diagonals of a spiral odd | Java program to find sum of diagonals of spiral matrix ; function returns sum of diagonals ; as order should be only odd we should pass only odd - integers ; Driver program to test
class GFG { static int spiralDiaSum ( int n ) { if ( n == 1 ) return 1 ; return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . print ( spiralDiaSum ( n ) ) ; } }