Symmetric Matrix Program In Java

Program   Symmetric Matrix In Java 2021

Symmetric Matrix Program In Java | Symmetric Matrix

Here is  the  Program  of Symmetric Matrix Program in Java

What Is Symmetric Matrix?

Symmetric matrix is a square matrix which is equal to its transpose. In the other words, if A[][] is a square matrix with (M x M) order, then this matrix is said to be symmetric if every element at ith row and jth column is equal to element at jth row and ith column i.e  A[i][j] == A[j][i].

We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊

import java.util.*;  
 class Symmetric_Matrix  
 {  
   public static void main()  
   {  
     Scanner sc=new Scanner(System.in);  
     System.out.println("Enter the number of Rows");  
     int r=sc.nextInt();  
     System.out.println("Enter the number of Columns");  
     int c=sc.nextInt();  
     int arr[][]=new int[r][c];  
     int brr[][]=new int[c][r];  
     int d=0;  
     System.out.println("Enter the elements of Matrix");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {          
         arr[i][j]=sc.nextInt();  
       }        
     }  
      for(int i=0;i<c;i++) //creating transpose  
     {  
       for(int j=0;j<r;j++)  
       {  
         brr[j][i]=arr[i][j];  
       }  
     }  
     System.out.println("Input Matrix Is:");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {          
         System.out.print(arr[i][j]+" ");  
         if(arr[i][j]!=brr[i][j])  
         {  
           d=1;  
         }  
       }  
       System.out.println("");       
     }  
     if(d==1)  
       System.out.println("THE GIVEN MATRIX IS NOT A SYMMETRIC MATRIX");  
     else  
       System.out.println("THE GIVEN MATRIX IS A SYMMETRIC MATRIX");  
   }  
 }  
 -------------  
 OUTPUT:-  
 -------------  
 Enter the number of Rows  
 4  
 Enter the number of Columns  
 4  
 Enter the elements of Matrix  
 1  
 5  
 6  
 9  
 8  
 7  
 5  
 3  
 2  
 4  
 1  
 5  
 3  
 6  
 2  
 9  
 Input Matrix Is:  
 1 5 6 9   
 8 7 5 3   
 2 4 1 5   
 3 6 2 9   
 THE GIVEN MATRIX IS NOT A SYMMETRIC MATRIX..  
 -------------------------------------------- 

Checkout:- Sort Matrix in Ascending Order Java

Checkout:-  Sorting Rows of Matrix in Descending Order Java

Post a Comment

0 Comments