{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MatriceLib

MatriceLib - class MatriceLib cfw METHOD display Displays...

This preview shows pages 1–2. Sign up to view the full content.

class MatriceLib { // METHOD display: Displays the content of a matrix // GIVENS: mat, a matrix of integers // RESULT: None // ASSUMPTIONS: the matrix is not empty public static void display (int[][] mat) { // DECLARATION OF VARIABLES / DATA DICTIONNARY int noRows, noCols; // INTERMEDIATES: size of mat int r, c; // INTERMEDIATES: Index for traversing the matrix // BODY OF THE ALGORITHM noRows = mat.length; noCols = mat[0].length; r = 0; while (r < noRows) { c = 0; while (c < noCols) { System.out.print(mat[r][c] + " "); c = c + 1; } System.out.println(); // go to the next row r = r + 1; } // RETURN RESULT: NONE } // METHOD compare: test the equality of two matrices // GIVENS: mat1 and mat2: two matrices of integers // RESULT: true is their content is equal // ASSUMPTIONS: the matrices are not empty public static boolean compare (int[][] mat1, int[][] mat2) { // DECLARATION OF VARIABLES / DATA DICTIONNARY int noRows1, noCols1; // INTERMEDIATES: size of mat1 int r, c; // INTERMEDIATES: Index for traversing the matrices boolean equals; // RESULT: true if mat1 and mat2 are equal // BODY OF THE ALGORITHM noRows1 = mat1.length;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}