Skip to content

Instantly share code, notes, and snippets.

@jesjos
Created November 1, 2010 21:03
Show Gist options
  • Save jesjos/658858 to your computer and use it in GitHub Desktop.
Save jesjos/658858 to your computer and use it in GitHub Desktop.
En matrismultiplikationsflärp
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