by Dinesh Thakur

 

import java.io.*;

class MultiplicationofMatrix
{
           
            public static void main(String args[]) throws IOException
            {
                        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
                        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++)
                                    {
                                                m=bf.readLine();
                                                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++)
                                    {
                                                m=bf.readLine();
                                                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();
                        }
            }
}

Multiplication of Two Matrix in Java Example