Java tutorial
//package com.java2s; public class Main { public static float[] naivMatrixMultiply(float[] B, float[] A) { int mA, nA, mB, nB; mA = nA = (int) Math.sqrt(A.length); mB = nB = (int) Math.sqrt(B.length); if (nA != mB) throw new RuntimeException("Illegal matrix dimensions."); float[] C = new float[mA * nB]; for (int i = 0; i < mA; i++) for (int j = 0; j < nB; j++) for (int k = 0; k < nA; k++) C[i + nA * j] += (A[i + nA * k] * B[k + nB * j]); return C; } }