•• 8. Write a method that returns the sum of a given row in a two-dimensional array. Complete this code: ArrayUtil.java 1 public class ArrayUtil 2 { /** 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) { 3 4 8 10 11 } 13 } 12 RowSumTester.java 1 public class RowSumTester 2 { public static void main(String[] args) { 4 6. int[][] counts = { 1, 0, 1 }, { 1, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 1 }, { 0, 1, 1 }, { 1, 1, 0 } 10 11 12 13 14 }; int sum = ArrayUtil.rowSum(counts, 5); 15 16 System.out.println(sum); System.out.println("Expected: 2"); 17 18 19 int[][] magicSquare = { { 16, 3, 2, 13 }, { 5, 10, 11, 8 }, { 9, 6, 7, 12 }, { 4, 15, 14, 1 }, }; 20 21 22 23 24 25 26 for (int row = 0; row <= 3; row++) { System.out.println(ArrayUtil. rowSum(magicSquare, row)); System.out.println("Expected: 34"); } 27 28 29 30 31 32 33 }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
•• 8. Write a method that returns the sum of a given row in a two-dimensional array. Complete this code:
ArrayUtil.java
1 public class ArrayUtil
2 {
/**
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)
{
3
4
8
10
11
}
13 }
12
RowSumTester.java
1 public class RowSumTester
2 {
public static void main(String[] args)
{
4
6.
int[][] counts =
{ 1, 0, 1 },
{ 1, 1, 0 },
{ 0, 0, 1 },
{ 1, 0, 0 },
{ 0, 1, 1 },
{ 0, 1, 1 },
{ 1, 1, 0 }
10
11
12
13
14
};
int sum = ArrayUtil.rowSum(counts, 5);
15
16
System.out.println(sum);
System.out.println("Expected: 2");
17
18
19
int[][] magicSquare = {
{ 16, 3, 2, 13 },
{ 5, 10, 11, 8 },
{ 9, 6, 7, 12 },
{ 4, 15, 14, 1 },
};
20
21
22
23
24
25
26
for (int row = 0; row <= 3; row++)
{
System.out.println(ArrayUtil. rowSum(magicSquare, row));
System.out.println("Expected: 34");
}
27
28
29
30
31
32
33 }
Transcribed Image Text:•• 8. Write a method that returns the sum of a given row in a two-dimensional array. Complete this code: ArrayUtil.java 1 public class ArrayUtil 2 { /** 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) { 3 4 8 10 11 } 13 } 12 RowSumTester.java 1 public class RowSumTester 2 { public static void main(String[] args) { 4 6. int[][] counts = { 1, 0, 1 }, { 1, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 1 }, { 0, 1, 1 }, { 1, 1, 0 } 10 11 12 13 14 }; int sum = ArrayUtil.rowSum(counts, 5); 15 16 System.out.println(sum); System.out.println("Expected: 2"); 17 18 19 int[][] magicSquare = { { 16, 3, 2, 13 }, { 5, 10, 11, 8 }, { 9, 6, 7, 12 }, { 4, 15, 14, 1 }, }; 20 21 22 23 24 25 26 for (int row = 0; row <= 3; row++) { System.out.println(ArrayUtil. rowSum(magicSquare, row)); System.out.println("Expected: 34"); } 27 28 29 30 31 32 33 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education