import java.io.*;
abstract class matrix
{
int a[][]=new int[4][4];
int b[][]=new int[4][4];
int c[][]=new int[4][4];
abstract void cal();
}
class derived extends matrix
{
int i,j,k,n;
public void get()
{
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter matrix size");
n=Integer.parseInt(cin.readLine());
System.out.println("Enter the first matrix");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=Integer.parseInt(cin.readLine());
}
}
System.out.println("Enter the second matrix");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=Integer.parseInt(cin.readLine());
}
}
}
catch(Exception e)
{
System.out.println("wrong data");
}
}
public void cal()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(""+c[i][j]);
System.out.print(" ");
}
System.out.println();
}
}
}
class abs_mtr_mul
{
public static void main(String args[])
{
derived d=new derived();
d.get();
d.cal();
}
}
abstract class matrix
{
int a[][]=new int[4][4];
int b[][]=new int[4][4];
int c[][]=new int[4][4];
abstract void cal();
}
class derived extends matrix
{
int i,j,k,n;
public void get()
{
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter matrix size");
n=Integer.parseInt(cin.readLine());
System.out.println("Enter the first matrix");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=Integer.parseInt(cin.readLine());
}
}
System.out.println("Enter the second matrix");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=Integer.parseInt(cin.readLine());
}
}
}
catch(Exception e)
{
System.out.println("wrong data");
}
}
public void cal()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(""+c[i][j]);
System.out.print(" ");
}
System.out.println();
}
}
}
class abs_mtr_mul
{
public static void main(String args[])
{
derived d=new derived();
d.get();
d.cal();
}
}
No comments:
Post a Comment