Question: public class ArrayUtil { /** Computes the sum of a given row in a two-dimensional array. @param values the array @param the row whose sum

public class ArrayUtil

{ /** Computes the sum of a given row in a two-dimensional array. @param values the array @param the row whose sum to compute @return the sum of the given row */ public static int rowSum(int[][] values, int row) { . . . } }

Use the following file:

RowSumTester.java

public class RowSumTester { public static void main(String[] args) { int[][] counts = { { 1, 0, 1 }, { 1, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 1 }, { 0, 1, 1 }, { 1, 1, 0 } }; int sum = ArrayUtil.rowSum(counts, 5); System.out.println(sum); System.out.println("Expected: 2"); int[][] magicSquare = { { 16, 3, 2, 13 }, { 5, 10, 11, 8 }, { 9, 6, 7, 12 }, { 4, 15, 14, 1 }, }; for (int row = 0; row <= 3; row++) { System.out.println(ArrayUtil.rowSum(magicSquare, row)); System.out.println("Expected: 34"); } } } 

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!