Question: There are two files attached to this assignment / DO NOT TOUCH RUNNER FILE : /**U8_L1_Activity_One.java** public class U8_L1_Activity_One { // Write diagSum method as

 There are two files attached to this assignment / DO NOT

There are two files attached to this assignment / DO NOT TOUCH RUNNER FILE :

/**U8_L1_Activity_One.java**\

public class U8_L1_Activity_One {

// Write diagSum method as described in the assignment

}

===========================================

/**runner_U8_L1_Activity_One**\

import java.util.Scanner; public class runner_U8_L1_Activity_One{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.println("Enter number of rows:"); int rows = scan.nextInt(); System.out.println("Enter number of columns:"); int cols = scan.nextInt(); int[][] mat = new int[rows][cols]; System.out.println("Enter values:"); for(int r = 0; r Write a public static method diagSum, which takes a 2d array of int values as a parameter, and returns the sum of the elements in the lead diagonal as an int value. The lead diagonal is defined as the diagonal line of values starting in the top left corner and proceeding one step right and down for each value until either the bottom or right edge of the array is reached. For example, in the array represented below, the numbers in red make up the lead diagonal. 2 4 5 8 1 1 6 5 3 4 5 2 Write your diagSum method in the U8_L1_Activity One class. Use the runner class to test your method but do not add a main method to your U8_L1_Activity One.java file or your code will not be scored correctly. Hint - think about what the row/column indices are for each element in the lead diagonal of the array above. What is the link between the two indices for each element

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!