Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The two-dimensional arrays m1 and m2 are identical if they have the same content

ID: 3567673 • Letter: T

Question

The two-dimensional arrays m1 and m2 are identical if they have the same contents. Write a method that returns true if m1 and m2 are identical, using the following header:

public static boolean equals(int[][] m1, int[][] m2)

Write a test Java program that prompts the user to enter two 3 * 3 arrays of integers
and displays whether the two are identical. Here are the sample runs.

Enter list1: 51 25 22 6 1 4 24 54 6 [Enter] (user input)
Enter list2: 51 22 25 6 1 4 24 54 6 [Enter] (user input)
The two arrays are identical

Enter list1: 51 5 22 6 1 4 24 54 6 [Enter] (user input)
Enter list2: 51 22 25 6 1 4 24 54 6 [Enter] (user input)
The two arrays are not identical

Explanation / Answer

Java program that prompts the user to enter two 3 * 3 arrays of integers

Import java.util.Arrays;

Public class ComparisonTableau {

/*This function returns true if two arrays are identical*/

Public static Boolean arrayIsEquals(final Object[][] array1, final object[][] array2) {

If(array1==null) {

Return(array2==null);

}

If(array2==null) {

Return false;

}

If(array1.length!=array2.length) {

Return false;

}

For(int i=0; i<array1.length; i++) {

If(!Arrays.equals(arry1[i], array2[i])) {

Return false;

}

}

Return true;

}

Public static void main(string[] argv)

{

Integer tab1[][]={{1,2,3},{4,5,6}};

Integer tab2[][]={{-1,-2,-3},{-4,-5,-6}};

Integer tab3[][]={{1,2,3},{4,5,6}};

System.out.println(