Question: JAVA Matrix 8. Write a method called sumCorners that computes the sum of the four corners of a given matrix. 9. Write a method called

JAVA

Matrix 8. Write a method called sumCorners that computes the sum of the four corners of a given matrix. 9. Write a method called diagonalsSum that computes the sum of the main diagonals (the values that create an X shape in a square matrix). 10. Write a method called isIdentity that determines whether the given matrix is an identity matrix. An identity matrix is defined by: a. A square matrix. b. All the elements of the principal diagonal are ones. c. All other elements are zeros. 11. Write a method called interiorSum that computes the sum of all elements not in the first and last row as well as the first and last column.

~~~~~~~~~~~~~~~ Part II: Test Matrix method ~~~~~~~~~~~~~~~~~~~~` ~~~~~~~~~Step #8: Test 'sumCorners' method Matrix has: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 After performing 'sumCorners', result is: 42

SKELETON CODE

public class Matrix {

// Computes the sum of the four corners of the matrix public static int sumCorners(int[][] m) { int result = 0; // Single row / column matrix // Single row / multi-column matrix // Multi-row / single-column matrix // General matrix return result; }

public static boolean isIdentity(int[][] m) {

//to be completed return true; }

public static int interiorSum(int[][] m) {

int sum = 0; //to be completed return sum; }

public static int diagonalsSum(int[][] m) {

int sum = 0; //to be completed return sum; }

public static String printMatrix(int[][] mx) {

String result = "";

for (int i = 0; i < mx.length; i++) { result += " "; for (int j = 0; j < mx[0].length; j++) { result += mx[i][j] + "\t"; }

}

return result;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!