Here you can find the source of printMatrix(int[][] M)
public static void printMatrix(int[][] M)
//package com.java2s; //License from project: Open Source License public class Main { public static void printMatrix(int[][] M) { if (M.length == 0 || M[0].length == 0) return; for (int i = 0; i < M.length; i++) { for (int j = 0; j < M[0].length; j++) { System.out.printf("%5d", M[i][j]); }//from w w w . j ava 2 s . co m System.out.println(); } } public static void printMatrix(boolean[][] M) { if (M.length == 0 || M[0].length == 0) return; for (int i = 0; i < M.length; i++) { for (int j = 0; j < M[0].length; j++) { System.out.printf("%5d", M[i][j] ? 1 : 0); } System.out.println(); } } public static void printMatrix(char[][] M) { if (M.length == 0 || M[0].length == 0) return; for (int i = 0; i < M.length; i++) { for (int j = 0; j < M[0].length; j++) { System.out.printf("%5c", M[i][j]); } System.out.println(); } } public static void printMatrix(Object[][] M, int padding) { if (M.length == 0 || M[0].length == 0) return; for (int i = 0; i < M.length; i++) { for (int j = 0; j < M[0].length; j++) { System.out.printf("%" + padding + "s", M[i][j].toString()); } System.out.println(); } } }