Skip to content

Instantly share code, notes, and snippets.

@Shubhra22
Last active December 12, 2022 21:16
Show Gist options
  • Save Shubhra22/20d170de0b52d4e25aecdeed3dbd2e94 to your computer and use it in GitHub Desktop.
Save Shubhra22/20d170de0b52d4e25aecdeed3dbd2e94 to your computer and use it in GitHub Desktop.
Write a method
public static int max(int[][] a)
that returns the maximum value in the 2d parameter array a.
Write a method
public static int rowSum(int[][] a, int x)
that returns the sum of the elements in Row x of a.
public static int columnSum(int[][] a, int x)
that returns the sum of the elements in Column x of a (careful with rows of different lengths!).
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.
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).
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).
Write a method
public static boolean isSquare(int[][] a)
that checks if the array is square (i.e. every row has the same length as a itself).
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.
Write a method
public static boolean isLatin(int[][] a)
that checks to see if the array is a Latin square. This means that it must be square (suppose it is n x n), and that each row and each column must contain the values 1, 2, ..., n with no repeats.
Some helper methods you may need for this example and the next are suggested in the tester code. Uncomment and run these tests if you implement these helper methods.
Write a method
public static boolean isSequence(int[][] a)
that checks to see if the array is square (suppose it is n x n), and contains each of the digits from 1 to n*n, eg. 1, 2, ..., 16 for a 4 x 4 array.
@prog9z
Copy link

prog9z commented Dec 12, 2022

Write a method
public static boolean isSequence(int[][] a)
that checks to see if the array is square........

please can you help me to answer the examp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment