// given two matrices, a and b, determine if they are equal in size, equal in size and number, transposed, or none // a transposed matrix is one in which the rows of one matrix are the columns of the other as in: // 1 2 3 // 4 5 6 // and // 1 4 // 2 5 // 3 6 public class MatrixComparison { public static void main(String[] args) { int[][] a = {{1, 2, 3}, {4, 5, 6}}; // assign the two matrices and their rows and columns, adjust these 3 lines to change the outcome of the progrma int[][] b = {{1, 2, 3}, {4, 5, 6}}; int aRows = 2, aColumns = 3, bRows = 2, bColumns = 3; if(equal(a, b, aRows, aColumns, bRows, bColumns)) System.out.println("The two matrices are equal"); // test for equal else if(equalSize(aRows, aColumns, bRows, bColumns)) System.out.println("The two matrices are equal size but not equal content"); // test for equal size (we know they won't equal in content or the previous if would have been true) else if(transpose(a, b, aRows, aColumns, bRows, bColumns)) System.out.println("The two matrices are transpositions of each other"); // test for transpositions else System.out.println("The two matrices have nothing to do with each other"); // default when none of the others are true } public static boolean equal(int[][] a, int[][] b, int c, int d, int e, int f) // do the contents of a and b match precisely? a has dimensions [c][d] and b has dimensions [e][f] { if(c!=e||d!=f) return false; // if not equal size, then no, not equal else { for(int i=0;i