0% found this document useful (0 votes)
4 views

Multiplication of Matrices

Uploaded by

ranganadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Multiplication of Matrices

Uploaded by

ranganadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Multiplication of matrices

import java.lang.System;

public class Matrix_multiplication

public static void main(String args[])

int n = 3;

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

int[][] b = { {2, 7, 5}, {1, 4, 3}, {1, 2, 1} };

int[][] c = new int[n][n];

System.out.println("Matrix A:");

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

System.out.print(a[i][j] + " ");

System.out.println();

System.out.println("Matrix B:");

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

System.out.print(b[i][j] + " ");

System.out.println();
}

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++){

for (int k = 0; k < n; k++) {

c[i][j] = c[i][j] + a[i][k] * b[k][j];

System.out.println("The product of two matrices is:");

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

System.out.print(c[i][j] + " ");

System.out.println();

Output

------

Matrix A:

523

263
691

Matrix B:

275

143

121

The product of two matrices is:

15 49 34

13 44 31

22 80 58

You might also like