# Multiplication of Two Matrix in Java Example

by Dinesh Thakur Category: array

```import java.io.*;

class MultiplicationofMatrix

{

public static void main(String args[]) throws IOException

{

int m1[][]=new int[2][4];

int m2[][]=new int[4][3];

int m3[][]=new int[2][3];

int i,j,k;

String m;

System.out.println("Enter elements of first matrix of order 2 x 4");

for(i=0;i<=1;i++)

{

for(j=0;j<=3;j++)

{

m1[i][j]=Integer.parseInt(m);

}

}

System.out.println("Enter elements of second matrix of order 4 x 3");

for(i=0;i<=3;i++)

{

for(j=0;j<=2;j++)

{

m2[i][j]=Integer.parseInt(m);

}

}

for(i=0;i<=1;i++)

{

for(j=0;j<=2;j++)

{

m3[i][j]=0;

for(k=0;k<=3;k++)

{

m3[i][j]=m3[i][j]+m1[i][k]*m2[k][j];

}

}

}

System.out.println("The first matrix entered is ");

for(i=0;i<=1;i++)

{

for(j=0;j<=3;j++)

{

System.out.print(m1[i][j]+"\t");

}

System.out.println();

}

System.out.println("The second matrix entered is ");

for(i=0;i<=3;i++)

{

for(j=0;j<=2;j++)

{

System.out.print(m2[i][j]+"\t");

}

System.out.println();

}

System.out.println("The multiplication of matrix is ");

for(i=0;i<=1;i++)

{

for(j=0;j<=2;j++)

{

System.out.print(m3[i][j]+"\t");

}

System.out.println();

}

}

}

```

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article