Created
September 21, 2019 13:29
-
-
Save AndreaNicola/5056bf5a117123efb92793385274481e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MatrixMultiply { | |
static void printMatrix(double[][] a) { | |
for (int i = 0; i < a.length; i++) { | |
for (int j = 0; j < a[0].length; j++) { | |
System.out.print(a[i][j] + " "); | |
} | |
System.out.println(); | |
} | |
System.out.println(); | |
} | |
static double[][] multiply(double[][] a, double[][] b) { | |
if (a[0].length != b.length) { | |
throw new RuntimeException("Matrix are not compatible"); | |
} | |
double[][] c = new double[a.length][b[0].length]; | |
for (int i = 0; i < c.length; i++) { | |
for (int j = 0; j < c[0].length; j++) { | |
for (int k =0 ; k < c[0].length; k++) { | |
c[i][j] = a[i][k] * b[k][j] + c[i][j]; | |
} | |
} | |
} | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment