Java Program to Check Two Matrices are Equal

Program To Determine Whether Two Matrices are Equal or Not

Java Program to Check Two Matrices are Equal

Here is  the Java Program to Check Two Matrices are Equal

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 Matrices_Are_Equal_Or_Not  
 {  
   public static void main()  
   {  
     int s=0;  
     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[r][c];  
     System.out.println("Enter the elements of First Matrix");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         arr[i][j]=sc.nextInt();  
       }  
     }  
     System.out.println("First Matrix is :");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         System.out.print(arr[i][j]+" ");   
       }  
       System.out.println("");  
     }  
     System.out.println("Enter the elements of Second Matrix");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         brr[i][j]=sc.nextInt();  
       }  
     }  
     System.out.println("Second Matrix is :");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         System.out.print(brr[i][j]+" ");   
       }  
       System.out.println("");  
     }  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         s=s+arr[i][j]+brr[i][j];  
       }  
     }  
     if(r==c)  
     System.out.println("Matrices are Equal");  
     else  
     System.out.println("Matrices are not Equal");  
   }  
 }  
 ------------  
 OUTPUT:-  
 ------------  
 Enter the number of Rows  
 3  
 Enter the number of Columns  
 3  
 Enter the elements of First Matrix  
 1  
 2  
 3  
 4  
 5  
 6  
 7  
 8  
 9  
 First Matrix is :  
 1 2 3   
 4 5 6   
 7 8 9   
 Enter the elements of Second Matrix  
 1  
 2  
 3  
 4  
 5  
 6  
 7  
 8  
 9  
 Second Matrix is :  
 1 2 3   
 4 5 6   
 7 8 9   
 Matrices are Equal   
 ------------------ 

Checkout:- Sum of Left Diagonal Elements of Matrix Java

Checkout:-  Mirror Image of Matrix ISC 2013 Practical Java

Post a Comment

0 Comments