Store the primary diagonal elements
ArrayList < Integer > priDiag = new ArrayList < Integer > ( ) ; while ( i < mat . length ) { priDiag . add ( mat [ i ] [ j ] ) ; i += 1 ; j += 1 ; } i = 0 ; j = mat . length - 1 ;