# Free Response Question 2: Multiply the Matrices

In this exercise, you'll multiply the two matrices.

## We'll cover the following

## Background

In high school, you likely have studied matrix multiplication and its properties. Hereâ€™s an article in case you donâ€™t remember it.

In this challenge, youâ€™re required to perform matrix multiplication with Java.

## Problem statement

**Intent**: Design a `multiply()`

function that takes two input matrices ( 2D arrays) and a resultant matrix (a 2D array) as parameters and returns `true`

or `false`

depending on the input matrices.

- Declare the header of the
`multiply`

method correctly. - If the number of columns of the first matrix is not equal to the number of rows of the second matrix, return
`false`

because multiplication isnâ€™t possible. - If the number of columns of the first matrix is equal to the number of rows of the second matrix, calculate the resultant matrix and return
`true`

. Update the resultant matrix right away in the method. As itâ€™s a reference object, the changes will automatically be seen outside the local scope.

### How do we multiply matrices?

Look at the equation below. The value of the resultant matrix, at the first row, first column, is calculated as:

product

_{11}= (matrix1_{11}* matrix2_{11}) + (matrix1_{12}* matrix2_{21}) + ... +(matrix1_{1m}* matrix2_{m1})Here:

- matrix1
_{11}is the value of matrix1 at the 1^{st}row and 1^{st}column. - matrix2
_{11}is the value of matrix2 at the 1^{st}row and 1^{st}column. - matrix1
_{12}is the value of matrix1 at the 1^{st}row and 2^{nd}column. - matrix2
_{21}is the value of matrix2 at the 2^{nd}row and 1^{st}column. - matrix1
_{1m}is the value of matrix1 at the 1^{st}row and m^{th}column - matrix2
_{m1}is the value of matrix2 at the m^{th}row and 1^{st}column

Get hands-on with 1200+ tech skills courses.