•• 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 }
•• 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
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 }](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fceeb6cea-7cf3-42e9-8e8e-acd0830d098b%2Fc9514059-0e56-4a94-89a2-07b0fee3e56e%2Fc0yjpc.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education