Code Below:


import java.util.*;
class multiplydda
{
    public static void main()
    {
        Scanner s=new Scanner(System.in);
        System.out.println("Enter rows and columns of arr1");
        int r1=s.nextInt();
        int c1=s.nextInt();
        
        System.out.println("Enter rows and columns of arr2");
        int r2=s.nextInt();
        int c2=s.nextInt();
        
        if (c1!=r2)
        {
            System.out.println("Non-compatible");
            System.exit(0);
        }
        
        int arr1[][]=new int[r1][c1];
        int arr2[][]=new int[r2][c2];
        int mularr[][]=new int[r1][c2];
        
        System.out.println("Enter elements of arr1");
        for (int i=0;i< r1;i++)
        {
            for (int j=0;j< c1;j++)
            {
                arr1[i][j]=s.nextInt();
            }
        }
        
        System.out.println("Enter elements of arr2");
        for (int i=0;i< r2;i++)
        {
            for (int j=0;j< c2;j++)
            {
                arr2[i][j]=s.nextInt();
            }
        }
        
        //Multliplication Part
        for (int i=0;i< r1;i++)
        {
            for (int j=0;j< c2;j++)
            {
                for (int k=0;k< c1;k++)
                {
                    mularr[i][j]=mularr[i][j]+(arr1[i][k]*arr2[k][j]);
                }
            }
        }
        
        System.out.println("Multliplication elements of arr1 and arr2");
        for (int i=0;i< r1;i++)
        {
            for (int j=0;j< c2;j++)
            {
                System.out.print(mularr[i][j]+"\t");
            }
            System.out.println();
        }
    }
}