Symmetric Matrix Check
This program checks if a matrix is symmetric.
Problem Statement
Write a Java program to check whether a 3x3 matrix is symmetric.
Source Code
| 1 | public class SymmetricMatrixCheck { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Symmetric Matrix Check"); |
| 4 | int[][] A = {{1,2,3},{2,4,5},{3,5,6}}; |
| 5 | boolean symmetric=true; |
| 6 | for(int i=0;i<3;i++){ |
| 7 | for(int j=0;j<3;j++){ |
| 8 | if(A[i][j]!=A[j][i]) symmetric=false; |
| 9 | } |
| 10 | } |
| 11 | if(symmetric) System.out.println("Matrix is symmetric"); |
| 12 | else System.out.println("Matrix is not symmetric"); |
| 13 | } |
| 14 | } |
Program Output
Eduinq Symmetric Matrix Check Matrix is symmetric
Explanation
A symmetric matrix has equal elements across the main diagonal, so nested loops compare A[i][j] with A[j][i] and set a flag to false on any mismatch, demonstrating symmetric matrix validation.