0% found this document useful (0 votes)
6 views1 page

Java Program for 3x3 Matrix Multiplication

This document demonstrates how to multiply two matrices in Java by initializing two 3x3 matrices a and b with identical values, creating a third matrix c to store the results, and using a nested for loop to iterate through the elements of a and b and sum their products based on their indices to populate the corresponding elements in c, thereby performing the multiplication of the two matrices and printing out the result.

Uploaded by

Abhishek__kr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Java Program for 3x3 Matrix Multiplication

This document demonstrates how to multiply two matrices in Java by initializing two 3x3 matrices a and b with identical values, creating a third matrix c to store the results, and using a nested for loop to iterate through the elements of a and b and sum their products based on their indices to populate the corresponding elements in c, thereby performing the multiplication of the two matrices and printing out the result.

Uploaded by

Abhishek__kr
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Matrix Multiplication

1. public class MatrixMultiplicationExample{


2. public static void main(String args[]){
3. //creating two matrices
4. int a[][]={{1,1,1},{2,2,2},{3,3,3}};
5. int b[][]={{1,1,1},{2,2,2},{3,3,3}};
6.
7. //creating another matrix to store the multiplication of two matrices
8. int c[][]=new int[3][3]; //3 rows and 3 columns
9.
10. //multiplying and printing multiplication of 2 matrices
11. for(int i=0;i<3;i++){
12. for(int j=0;j<3;j++){
13. c[i][j]=0;
14. for(int k=0;k<3;k++)
15. {
16. c[i][j]+=a[i][k]*b[k][j];
17. }//end of k loop
18. [Link](c[i][j]+" "); //printing matrix element
19. }//end of j loop
20. [Link]();//new line
21. }
22. }}

You might also like