Symmetric Matrix Extended Check
This program checks if a matrix is symmetric and prints mismatched positions.
Problem Statement
Write a Java program to check whether a 3x3 matrix is symmetric and display mismatched positions if not.
Source Code
| 1 | public class SymmetricMatrixExtendedCheck { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Symmetric Matrix Extended Check"); |
| 4 | int[][] A = {{1,2,3},{2,4,5},{4,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]){ |
| 9 | System.out.println("Mismatch at ("+i+","+j+")"); |
| 10 | symmetric=false; |
| 11 | } |
| 12 | } |
| 13 | } |
| 14 | if(symmetric) System.out.println("Matrix is symmetric"); |
| 15 | else System.out.println("Matrix is not symmetric"); |
| 16 | } |
| 17 | } |
Program Output
Eduinq Symmetric Matrix Extended Check Mismatch at (2,0) Matrix is not symmetric
Explanation
Symmetric matrices require A[i][j] == A[j][i], and nested loops compare each pair, printing the exact position whenever a mismatch is found, together providing extended validation with mismatch reporting.