Here you can find the source of printMatrix(Object[][] matrix)
Parameter | Description |
---|---|
matrix | Matrix to be printed |
public static String printMatrix(Object[][] matrix)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww . j av a 2s . co m * Prints a matrix to console * @param matrix Matrix to be printed * @return Printed string */ public static String printMatrix(Object[][] matrix) { StringBuilder builder = new StringBuilder(""); int rowCount = matrix.length; if (rowCount == 0) { System.out.println("Matrix is empty"); return "Matrix is empty"; } int columnCount = matrix[0].length; for (int i = 0; i < rowCount; i++) { builder.append("["); for (int j = 0; j < columnCount; j++) { builder.append(matrix[i][j]).append(j == columnCount - 1 ? "" : ","); } builder.append("]\n"); } System.out.println(builder.toString()); return builder.toString(); } }