I have the following arrays in java, i would like to multiply array_x columns by array_y rows to finally create array_z values
aray_x array_y array_z
4|9 4|11|12|14 |
--- ---------- -----
8|7 13|9|22|7 |
--- -----
3|2 |
--- -----
9|1 |
my trial code listing public class Multiplication {
public static void main(String[] args) {
int array_x[][] = {{9, 8}, {2, 17}, {49, 4}, {13, 119}, {2, 19}, {11, 47}, {3, 73}};
int[][] array_y = new int[][]{{4, 11, 12, 14}, {13, 9, 22, 7}};
int array_z[][] = new int[4][2];
for (int i = 0; i < array_x.length; i++) {
for (int j = 0; j < array_x.length; j++) {
array_z[i][j] = array_x[i][j] * array_y[j][i];
System.out.print(" "+array_z[i][j]);
}
}
}
}
How do i achieve this - That; The 1st column of array_z is populated by the multiples of the 1st column of array_x and the 1st row of array_y. e.g 4x4=16, 8x11=88, thius array_x * array_y =array_z The 2nd column of array_z is populated by the multiples of the 2nd column of array_x and the 2nd row of array_y.