Text Practice Mode
For Java Programmer
created Jan 12th 2023, 15:21 by Veer Bharat Roy
0
91 words
2 completed
0
Rating visible after 3 or more votes
saving score / loading statistics ...
00:00
[3] Java Program to multiply two matrices
public class MatrixMultiplicationExample{
public static void mani(String args[]){
//creating two matrices
int a[][]={{1, 1, 1},{2,2,2},{3,3,3}};
int b[][]={{1, 1, 1},{2,2,2},{3,3,3}};
//creating another matrix to store the multiplication of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns
//multiplying and printing multiplication of 2 matrices
for(int =0;i<3;i++){
for(int j=0;j<3;j++){
c[i][i]=0;
for(int k=0;k<3;k++)
{
c[i][i]=0;
for(int k=0;k<3;k++)
{
c[i][j]+=a[i][k][j];
}//end of k loop
System.out.print(c[i][j]+""); //printing matrix element
}//end of j loop
System.out.println();//new line
}
}}
Output
6 6 6
12 12 12
18 18 18
public class MatrixMultiplicationExample{
public static void mani(String args[]){
//creating two matrices
int a[][]={{1, 1, 1},{2,2,2},{3,3,3}};
int b[][]={{1, 1, 1},{2,2,2},{3,3,3}};
//creating another matrix to store the multiplication of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns
//multiplying and printing multiplication of 2 matrices
for(int =0;i<3;i++){
for(int j=0;j<3;j++){
c[i][i]=0;
for(int k=0;k<3;k++)
{
c[i][i]=0;
for(int k=0;k<3;k++)
{
c[i][j]+=a[i][k][j];
}//end of k loop
System.out.print(c[i][j]+""); //printing matrix element
}//end of j loop
System.out.println();//new line
}
}}
Output
6 6 6
12 12 12
18 18 18
