[15 pts] A matrix is symmetric if, for each i and
j, ai,j =
aj,i.
The following is an example of a symmetric matrix.
0 | 23 | 45 |
23 | 10 | 36 |
46 | 36 | 20 |
Complete the following method so that it returns true only if the two-dimensional array parameter mat is symmetric. Your solution may assume that the matrix is square (as many columns as rows).
(Your solution shouldn't really be this long!)public static boolean isSymmetric(int[][] mat) { }
public static boolean isSymmetric(int[][] mat) { for(int i = 0; i < mat.length; i++) { for(int j = 0; j < mat.length; j++) { if(mat[i][j] != mat[j][i]) return false; } } return true; }