Here is the Java Program to Check Two Matrices are Equal
Checkout:- Java Program to Find Sum of Each Column of Matrix
Checkout:- Sum of Right Diagonal Elements of a Matrix
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
0 Comments
Just write down your question to get the answer...