0% found this document useful (0 votes)
7 views1 page

2d Array Practice.

The document outlines a series of method specifications for a 2D integer array in Java. It includes methods to find the maximum value, calculate row and column sums, check for row and column magic properties, determine if the array is square, and verify if it is a magic square. Each method is expected to function correctly based on the assumptions provided.

Uploaded by

srusti.pink
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

2d Array Practice.

The document outlines a series of method specifications for a 2D integer array in Java. It includes methods to find the maximum value, calculate row and column sums, check for row and column magic properties, determine if the array is square, and verify if it is a magic square. Each method is expected to function correctly based on the assumptions provided.

Uploaded by

srusti.pink
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Write a method public static int max(int[][] a)


that returns the maximum value in the 2d parameter array a.

2. Write a method public static int rowSum(int[][] a, int x)


that returns the sum of the elements in Row x of a.

3. Write a method public static int columnSum(int[][] a, int x)


that returns the sum of the elements in Column x of a.

4. Write a method public static int[] allRowSums(int[][] a)


that calculates the row sum for every row and returns each of the values in an array. Index i of the
return array contains the sum of elements in row i. You should assume that rowSum is working as
intended.

5. Write a method public static boolean isRowMagic(int[][] a)


that checks if the array is row-magic (this means that every row has the same row sum). You should
assume that allRowSums is working as intended.

6. Write a method public static boolean isColumnMagic(int[][] a)


that checks if the array is column-magic (this means that every column has the same column sum).
You should assume that columnSum is working as intended.

7. Write a method public static boolean isSquare(int[][] a)


that checks if the array is square (i.e. number of cols is the same as the number of rows).

8. Write a method public static boolean isMagic(int[][] a)


that checks if the array is a magic square. This means that it must be square, and that all row sums,
all column sums, and the two diagonal-sums must all be equal. You should assume that all
methods that you can use to help you are working as intended.

You might also like