Multiplication of Matrix in Java

Multiplication of matrix in java program. The first matrix’s number of columns must equal the number of rows in the second matrix. The resulting matrix, known as the matrix product, has the first matrix’s number of rows and the second matrix’s number of columns.

public class Main
{
public static void main(String args[])
{
int a[][]={{10,10,10},{20,20,20},{30,30,30}};
int b[][]={{10,10,10},{20,20,20},{30,30,30}};
int c[][]=new int[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=0;
for(int k=0;k<3;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}

 

Output:

600 600 600
1200 1200 1200
1800 1800 1800

What is Multiplication of Matrix in Java Program

A mathematical operation that is, at its most basic level, an abbreviated procedure of adding an integer to zero a defined number of times, which is then extended to other numbers using principles that apply to integers.

What is Multiplication of matrix

The first matrix’s column count must match the second matrix’s row count. The matrix product has the first matrix’s number of rows and the second matrix’s number of columns. The 2×2 Matrix is a decision-making technique in which possibilities are plotted on a two-by-two matrix. A four blocker is also known as a magic quadrant. A simple square divided into four equal quadrants forms the matrix diagram. Each axis indicates a criterion for making a decision, such as price or effort.

What is for loop in java program

A for statement in Java creates loops with an automatically maintained counter variable. The for statement allows you to specify an initial value for the counter variable, the amount that will be added to it on each loop execution, and the condition that will be evaluated to determine when the loop should end.

Similar Programs