Created
November 1, 2010 21:03
-
-
Save jesjos/658858 to your computer and use it in GitHub Desktop.
En matrismultiplikationsflärp
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
class MMult { | |
public static int[][] mult(int[][] a, int[][] b) { | |
int rows = a.length; | |
int elements = a[0].length; | |
int columns = b[0].length; | |
int[][] results = new int[rows][columns]; | |
for (int n = 0; n < rows; n++) { | |
for (int m = 0; m < rows; m++) { | |
for (int i = 0; i < elements; i++) { | |
results[n][m] += a[n][i]*b[i][m]; | |
} | |
} | |
} | |
return results; | |
} | |
public static void main(String[] args) { | |
int[][] a = {{1,2,3},{4,5,6}}; | |
int[][] b = {{1,2},{3,4},{5,6}}; | |
int[][] c = MMult.mult(a,b); | |
for(int[] x : c) { | |
String out = ""; | |
for(int y : x) { | |
out += y + " "; | |
} | |
System.out.println(out); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment