Matrix Multiplication

Java Programming

Java Programming Examples

import java.io.*;

class mulmatrix {

	/* Constructor */
	mulmatrix(int a[ ][ ], int b[ ][ ]) {
		int ans[ ][ ] = new int[3][3];
		System.out.println("Matrix Multiplication");
		for(int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++) {
				ans[i][j] = 0;
				for(int k = 0; k < 3; k++)
				ans[i][j] += a[i][k] * b[k][j];
			}
		for(int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++)
			System.out.print(ans[i][j]+"\t");
			System.out.println("");
		}
	}
}

class matrix {
	public static void main(String args[ ]) {
		int a[ ][ ] = {{1,2,3},{4,5,6},{7,8,9}};
		int b[ ][ ] = {{4,4,4},{4,4,4},{4,4,4}};
		mulmatrix mulmat = new mulmatrix(a, b);
	}
}


          /****** Output ******/
          

Matrix Multiplication


24 24 24


60 60 60


96 96 96

Learn more about Matrix Multiplication