This question involves reasoning about one-dimensional and two-dimensional arrays of integers. You will write three static methods, all of which are in a single enclosing class, named DiverseArray (not shown). The first method returns the sum of the values of a one-dimensional array; the second method returns an array that represents the sums of the rows of a two-dimensional array; and the third method analyzes row sums.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
Assume that arraySum works as specified, regardless of what you wrote in part (a). You must use arraySum appropriately to receive full
credit.
Complete method rowSums below.
/** Returns a one-dimensional array in which the entry at index k is the sum of
* the entries of row k of the two-dimensional array arr2D.
* /
public static int [] rowSums(int [][ ] arr2D)
Submit
(c) A two-dimensional array is diverse if no two of its rows have entries that sum to the same value. In the following examples, the array
mat1 is diverse because each row sum is different, but the array mat2 is not diverse because the first and last rows have the same sum.
mat1
1
2
3
4
Row sums
1
3
2
7
3
16
1
10
10
4
32
2
5
3
5
9.
28
7
6.
4
1
20
mat2
1
2
3
4
Row sums
1
3
14
1
12
7
1
35
8.
11
10
36
2
3
14
Write a static method isDiverse that determines whether or not a given two-dimensional array is diverse. The method has one parameter: a
two-dimensional array arr2D of int values. The method should return true if all the row sums in the given array are unique; otherwise, it
should return false. In the arrays shown above, the call isDiverse (mat1) returns true and the call isDiverse(mat2) returns false.
Methods written in this question
public static int arraySum (int [] arr)
public static int[] rowSums (int []] arr2D)
public static boolean isDiverse(int [] [] arr2D)
Assume that arraySum and rowSums work as specified, regardless of what you wrote in parts (a) and(b). You must use rowSums
appropriately to receive full credit.
Complete method isDiverse below.
/** Returns true if all rows in arr2D have different row sums;
* false otherwise.
* /public static boolean isDiverse(int [][] arr2D)
2.
4.
2.
1.
2.
Transcribed Image Text:Assume that arraySum works as specified, regardless of what you wrote in part (a). You must use arraySum appropriately to receive full credit. Complete method rowSums below. /** Returns a one-dimensional array in which the entry at index k is the sum of * the entries of row k of the two-dimensional array arr2D. * / public static int [] rowSums(int [][ ] arr2D) Submit (c) A two-dimensional array is diverse if no two of its rows have entries that sum to the same value. In the following examples, the array mat1 is diverse because each row sum is different, but the array mat2 is not diverse because the first and last rows have the same sum. mat1 1 2 3 4 Row sums 1 3 2 7 3 16 1 10 10 4 32 2 5 3 5 9. 28 7 6. 4 1 20 mat2 1 2 3 4 Row sums 1 3 14 1 12 7 1 35 8. 11 10 36 2 3 14 Write a static method isDiverse that determines whether or not a given two-dimensional array is diverse. The method has one parameter: a two-dimensional array arr2D of int values. The method should return true if all the row sums in the given array are unique; otherwise, it should return false. In the arrays shown above, the call isDiverse (mat1) returns true and the call isDiverse(mat2) returns false. Methods written in this question public static int arraySum (int [] arr) public static int[] rowSums (int []] arr2D) public static boolean isDiverse(int [] [] arr2D) Assume that arraySum and rowSums work as specified, regardless of what you wrote in parts (a) and(b). You must use rowSums appropriately to receive full credit. Complete method isDiverse below. /** Returns true if all rows in arr2D have different row sums; * false otherwise. * /public static boolean isDiverse(int [][] arr2D) 2. 4. 2. 1. 2.
This question involves reasoning about one-dimensional and two-dimensional arrays of integers. You will write three static methods, all of
which are in a single enclosing class, named DiverseArray (not shown). The first method returns the sum of the values of a one-dimensional
array; the second method returns an array that represents the sums of the rows of a two-dimensional array; and the third method analyzes
row sums.
(a) Write a static method arraySum that calculates and returns the sum of the entries in a specified one-dimensional array. The following
example shows an array arr1 and the value returned by a call to arraySum.
Value returned by
arraySum (arr1)
arrl
Submit
1
3
4
3
7
16
Complete method arraySum below.
/ ** Returns the sum of the entries in the one-dimensional array arr.
* /
public static int arraySum (int [] arr)
(b) Write a static method rowSums that calculates the sums of each of the rows in a given two-dimensional array and returns these sums in
a one-dimensional array. The method has one parameter, a two-dimensional array arr2D of int values. The array is in row-major order: arr2D [
r][c]is the entry at row r and column c. The method returns a one-dimensional array with one entry for each row of arr2D such that each
entry is the sum of the corresponding row in arr2D. As a reminder, each row of a two-dimensional array is a one-dimensional array.
For example, if mat1 is the array represented by the following table, the call rowSums(mat1) returns the array {16, 32, 28, 20}.
mat1
1
2
3
4
7
1
10
10
4
6.
2
3
9.
6.
3
7
6.
4
2
1
Methods written in this question
public static int arraySum (int [] arr)
public static int[] rowSums (int []0 arr2D)
public static boolean isDiverse (int[][] arr2D)
3.
1.
Transcribed Image Text:This question involves reasoning about one-dimensional and two-dimensional arrays of integers. You will write three static methods, all of which are in a single enclosing class, named DiverseArray (not shown). The first method returns the sum of the values of a one-dimensional array; the second method returns an array that represents the sums of the rows of a two-dimensional array; and the third method analyzes row sums. (a) Write a static method arraySum that calculates and returns the sum of the entries in a specified one-dimensional array. The following example shows an array arr1 and the value returned by a call to arraySum. Value returned by arraySum (arr1) arrl Submit 1 3 4 3 7 16 Complete method arraySum below. / ** Returns the sum of the entries in the one-dimensional array arr. * / public static int arraySum (int [] arr) (b) Write a static method rowSums that calculates the sums of each of the rows in a given two-dimensional array and returns these sums in a one-dimensional array. The method has one parameter, a two-dimensional array arr2D of int values. The array is in row-major order: arr2D [ r][c]is the entry at row r and column c. The method returns a one-dimensional array with one entry for each row of arr2D such that each entry is the sum of the corresponding row in arr2D. As a reminder, each row of a two-dimensional array is a one-dimensional array. For example, if mat1 is the array represented by the following table, the call rowSums(mat1) returns the array {16, 32, 28, 20}. mat1 1 2 3 4 7 1 10 10 4 6. 2 3 9. 6. 3 7 6. 4 2 1 Methods written in this question public static int arraySum (int [] arr) public static int[] rowSums (int []0 arr2D) public static boolean isDiverse (int[][] arr2D) 3. 1.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY