这个三重for循环是有点小牛哦……
掌握知识
- for循环的进阶应用
- 静态数组初始化
- 二维数组灵活控制
通关源码
class Transpose{
public static void main(String[] args){
int[][] arr1 = { {5,6,7},
{15,65,43},
{32,43,22},
{11,88,6},
{4,98,66}};
int[][] arr2 = { {94,65,31,87,21},
{48,2,0,71,98},
{38,29,66,88,100}};
int[][] arr3 = new int[5][5];
//目的,arr3[0][0] = 5 * 94 + 6 * 48 + 7 * 38;甭说了,我自己都懵
for (int i = 0 ; i < 5 ; i++){
for (int j = 0; j < 5; j++){
for (int k = 0 ; k < 3; k++){
arr3[i][j] = arr3[i][j] + arr1[i][k] * arr2[k][j];
}
}
}
for (int i = 0; i < arr3.length; i++){
for (int j = 0; j < arr3[i].length; j++){
System.out.print( arr3[i][j]+ " ");
}
System.out.println();
}
}
}