0% found this document useful (0 votes)
6 views4 pages

Java Program to Check Matrix Equality

The document contains a Java class named EqMat that defines a matrix and includes methods for reading matrix elements, checking if two matrices are equal, and printing the matrix. The main method creates two instances of EqMat, reads their elements from user input, and checks for equality. If the matrices are equal, it prints both matrices; otherwise, it indicates they are not equal.

Uploaded by

krishna007733
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Java Program to Check Matrix Equality

The document contains a Java class named EqMat that defines a matrix and includes methods for reading matrix elements, checking if two matrices are equal, and printing the matrix. The main method creates two instances of EqMat, reads their elements from user input, and checks for equality. If the matrices are equal, it prints both matrices; otherwise, it indicates they are not equal.

Uploaded by

krishna007733
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;
class EqMat
{
int a[][];
int m;
int n;
static Scanner sc=new Scanner([Link]);
EqMat(int mm,int nn)
{
m=mm;
n=nn;
a=new int[m][n];
}
void readarray()
{
[Link]("enter" + (m*n) + "elements" );
for (int i=0;i<m;i++)
for (int j=0;j<n;j++)
a[i][j]=[Link]();
}
int check(EqMat P,EqMat Q)
{
for (int i=0;i<P.m;i++)
for (int j=0;j<P.n;j++)
{
if (P.a[i][j]!=Q.a[i][j])
return 0;
}
return 1;
}
void print()
{
for (int i=0;i<m;i++)
{
for (int j=0;j<n;j++)
{
[Link](a[i][j]+"\t");
}
[Link]();
}
}
public static void main()
{
EqMat ob1=new EqMat(2,2);
EqMat ob2=new EqMat(2,2);
[Link]("enter nos for the Ist Matrix");
[Link]();
[Link]("enter nos for the 2nd Matrix");
[Link]();
if ([Link](ob1,ob2)==1)
{
[Link]("Equal Matrix");
[Link]("First Matrix");
[Link]();
[Link]("Second Matrix");
[Link]();
}
else
[Link]("not equal");
}
}

You might also like