logo CodeStepByStep logo

matrixSum

Write a method named matrixSum that accepts as parameters two 2D arrays of integers, 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. For example, if A is {{1, 2, 3}, {4, 4, 4}} and B is {{5, 5, 6}, {0, -1, 2}}, the call of matrixSum(a, b) should return {{6, 7, 9}, {4, 3, 6}}. You may assume that the arrays passed as parameters have the same dimensions.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.