Java Program to Multiply Two Matrices

Java Program to Multiply Two Matrices

Java Program to Multiply Two Matrices | Multiplication of Two Matrix

Here is  the Java Program Multiplication Of Two Matrix 

We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊
 import java.util.*;  
 class Multiplication_of_two_Matrix  
 {  
   public static void main()  
   {  
     Scanner sc=new Scanner(System.in);    
     System.out.println("Enter the number of Rows");  
     int r=sc.nextInt();  
     System.out.println("Enter the number of Columns");  
     int c=sc.nextInt();  
     int arr[][]=new int[r][c];  
     int brr[][]=new int[r][c];  
     int crr[][]=new int[r][c];  
     System.out.println("Enter the elements of First Matrix");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         arr[i][j]=sc.nextInt();  
       }  
     }  
     System.out.println("First Matrix is :");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         System.out.print(arr[i][j]+" ");   
       }  
       System.out.println("");  
     }  
     System.out.println("Enter the elements of Second Matrix");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         brr[i][j]=sc.nextInt();  
       }  
     }  
     System.out.println("Second Matrix is :");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         System.out.print(brr[i][j]+" ");   
       }  
       System.out.println("");  
     }  
      System.out.println("Third Matrix is :");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         crr[i][j]=arr[i][j]*brr[i][j];    
         System.out.print(crr[i][j]+" ");   
       }  
         System.out.println("");  
     }  
   }  
 }  
 ------------  
 OUTPUT:-  
 ------------  
 Enter the number of Rows  
 3  
 Enter the number of Columns  
 3  
 Enter the elements of First Matrix  
 1  
 5  
 2  
 3  
 6  
 4  
 7  
 8  
 9  
 First Matrix is :  
 1 5 2   
 3 6 4   
 7 8 9   
 Enter the elements of Second Matrix  
 5  
 2  
 3  
 6  
 4  
 7  
 8  
 9  
 6  
 Second Matrix is :  
 5 2 3   
 6 4 7   
 8 9 6   
 Third Matrix is :  
 5 10 6   
 18 24 28   
 56 72 54   
 ----------------  

Checkout:-Sum of Left Diagonal Elements of Matrix Java

Checkout:-  Mirror Image of Matrix ISC 2013 Practical Java 

Post a Comment

0 Comments