Krivalar Tutorials 
Krivalar Tutorials


Matrix Multiplication - Java Program

Each element of the result matrix is sum of the product of the elements in the corresponding row of the first matrix and corresponding column of the second matrix.

Matrix 1:
a11 a12 a13
a21 a22 a23
a31 a32 a33

Matrix 2:
b11 b12 b13
b21 b22 b23
b31 b32 b33


c11 =(a11*b11+ a12*b21 + a13*b31)
c12 =(a11*b12+ a12*b22 + a13*b32)

Java Program - Matrix Multiplication


public class MatrixMultiplication {

	public static void main (String args[]) {

		int a[][] = {
					{1,2,3},
					{4,5,6},
					{7,8,9}};

		int b[][] = {
					{1,0,1},
					{0,1,1},
					{1,1,0}};

		int c[][] = new int[3][3];

		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				c[i][j] =0;
				for(int k=0;k<3;k++) {
				c[i][j]=c[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("" + c[i][j] + " ");
			}
			System.out.println();
		}
	}

}


























Searching using Binary Search Tree