Java Matrix Print printMatrix(Object[][] matrix)

Here you can find the source of printMatrix(Object[][] matrix)

Description

Displays a matrix of Objects.

License

BSD License

Parameter

Parameter Description
matrix a parameter

Declaration

public static void printMatrix(Object[][] matrix) 

Method Source Code

//package com.java2s;
/**//from  w ww.  j  a  va  2  s . co m
 * <p>
 * This software is distributed under the <a href="http://hci.stanford.edu/research/copyright.txt">
 * BSD License</a>.
 * </p>
 * 
 * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu)
 */

public class Main {
    /**
     * Displays a matrix of Objects.
     * 
     * @param matrix
     */
    public static void printMatrix(Object[][] matrix) {
        int numRows = matrix[0].length;
        int numCols = matrix.length;
        System.out.println("Matrix of " + matrix[0][0].getClass().getSimpleName() + ": [");
        for (int y = 0; y < numRows; y++) {
            System.out.print("    row " + y + ": [");
            for (int x = 0; x < numCols; x++) {
                System.out.print(matrix[x][y]);
                if (x != numCols - 1) {
                    System.out.print(", ");
                }
            }
            System.out.println("]");
        }
        System.out.println("]");
    }
}

Related

  1. printMatrix(int[][] M)
  2. printMatrix(int[][] matrix)
  3. printMatrix(int[][] s)
  4. printMatrix(int[][] target)
  5. printMatrix(Object[][] matrix)
  6. printMatrix(Object[][] matrix)
  7. printMatrix(PrintStream out, double[][] matrix)
  8. printMatrixGeneric(boolean[][] matrix)