java二维数组的个数
Here, We have to find the multiplication of the two matrix by moving forward direction in row major (row by row) order in one matrix and by backward direction in row major order in second one i.e. multiplying first element of one matrix with the last element of second one, second element of first one with the second last element of second one and so on…
在这里,我们必须通过以下方式找到两个矩阵的乘法:在一个矩阵中按行主要(行)顺序向前移动,在第二个矩阵中按行主要顺序向后移动,即将一个矩阵的第一个元素与最后一个元素相乘第二个元素的第一个元素,第二个元素的倒数第二个元素的第二个元素,依此类推…
Example:
例:
First matrix (X)
8 9 5
5 6 3
4 9 7
Second matrix (Y)
6 8 10
12 4 5
3 17 20
We have to multiply like that,
我们必须那样繁衍,
First element of first matrix (X) with the last one of second matrix (Y) → 8*20 and save it to the first index of new matrix. Then , 9*17 and save it to the 2nd index of new one and so on...
第一个矩阵( X )的第一个元素与第二个矩阵( Y )的最后一个元素→8 * 20,并将其保存到新矩阵的第一个索引中。 然后,9 * 17并将其保存到新索引的第二个索引,依此类推...
The new Matrix Z is
新的Matrix Z是
160 153 15
24 25 36
40 72 42
Program:
程序:
public class Multiplication
{
public static void main(String[] args)
{
//first matrix
int x[][]={{8,9,5},{5,6,3},{4,9,7}};
//second matrix
int y[][]={{6,8,10},{12,4,5},{3,17,20}};
//matrix which stores multiplication of the two
int z[][]=new int[3][3];
for(int i=0,j=2;i<3;i++,j--)
for(int k=0,l=2;k<3;k++,l--)
z[i][k]=x[i][k]*y[j][l];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(z[i][j]+" ");
System.out.println();
}
}
}
Output
输出量
![Multiplication of two 2-D Arrays](https://www.includehelp.com/java-programs/Images/multiplication-of-two-2-d-arrays-output.jpg)
java二维数组的个数