Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method named matrixAdd that accepts a pair of two-dimensional arrays of

ID: 3530165 • Letter: W

Question

Write a method named matrixAdd that accepts a pair of two-dimensional arrays of integers as parameters, treats the arrays as 2D matrices and adds them, returning the result. The sum of two matrices A and B is a matrix C where for every row i and column j, Cij = Aij + Bij. You may assume that the arrays passed as parameters have the same dimensions. This is what I have so far: public static int [][] matrixAdd(int [][]array1, int [][]array2) { int [][] c = new int[array1.length][array1[0].length]; if(c== for(int row=0; row

Explanation / Answer

public static int [][] matrixAdd(int [][]array1, int [][]array2) {

int [][] c = new int[array1.length][array1[0].length];

int i,j;

for(i=0;i<array1.length;i++)

for(j=0;j<array1[0].length;j++)

c[i][j] = array1[i][j] + array2[i][j];

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote