Write a method that sums all the numbers in the major diagonal in an n n × matrix of double values using the following header: public static double sumMajorDiagonal(double[][] m) Write a test program that reads a 4-by-4 matrix and displays the sum of all its elements on the major diagonal. Here is a sample run: Enter a 4-by-4 matrix row by row: 1 2 3 4.0 5 6.5 7 8 9 10 11 12 13 14 15 16 2 Sum of the elements in the major diagonal is 34.5
Your code should look like this:
public class PFinal1 {
public static void main(String[] args) { // WRITE YOUR CODE } public static double sumMajorDiagonal(double[][] m) { // WRITE YOUR CODE } }