<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">public class matrix_mul {
    public static void main(String args[]) {

	double[][] A = {
	    {1, 2},
	    {3, 4}
	};

	double[][] B = {
	    {1, -1},
	    {2,  0}
	};
	
	// A[r][k]*B[k][c] = C[r][c]
	// could also check all column lengths of B to be safe
	double[][] C = new double[A.length][B[1].length];

	for(int i=0; i&lt;A.length; i++) {		// rows
	    for(int j=0; j&lt;A[i].length; j++) {	// cols
		C[i][j] = 0;

		if (A.length != B[j].length) {
		    System.err.println("# rows of A must = # cols of B");
		    System.exit(0);
		}

		for(int k=0; k&lt;B[j].length; k++)
		    C[i][j] += A[i][k]*B[k][j];
		
		System.out.print(C[i][j] + " ");
	    }

	    System.out.println();
	}

    } // method main
    
} // class matrix_mul	       
		
</pre></body></html>