Mon Sep 13 2021

Matrix Multiplication

File Name: matrix-multiplication.java

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

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.