To check whether a given matrix is Symmetric or not in Java

Hello everyone! here we will learn about how to check whether a given matrix is symmetric or not in Java. In order to check for the matrix to be symmetric, it should satisfy two conditions.

1. It should be a square matrix.

2. Its transpose should retain the original matrix.

Also read;

Check whether a matrix is symmetric or not!

import java.util.*;
public class Main {
  public static void main(String[] args) {
  Scanner s=new Scanner(;
  int r,c;
  System.out.println("enter no of rows and columns");
  int[][]	a=new int[r][c];
  int[][]	b=new int[r][c];
  System.out.println("enter the matrix elements");
  for(int i=0;i<r;i++) {
    for(int j=0;j<c;j++)
 if(r==c) {	
  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) {
 int x=0;
 for(int i=0;i<r;i++) 
   for(int j=0;j<c;j++) 



enter no of rows and columns
enter the matrix elements
1 2 3
2 1 4
3 4 3

From the above example, first, we will read the no of rows and no of columns of the matrix. And then read the elements of the matrix. Now find the transpose of the given matrix. In order to find the transpose of a matrix, first declare an array of the same size to that of the given matrix. Then store the values at their reverse indices. And then compare the actual array and the transpose, if both the matrices are the same then the matrix is symmetric. Note that the matrix declared is a square matrix.

I hope the above example with an explanation is clear and easy to understand how to check if a matrix is Symmetric or not in Java. And you can read the matrix values dynamically by using a Scanner object with no confusion.

Leave a Reply

Your email address will not be published. Required fields are marked *