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

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

Description

print Matrix

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void printMatrix(int[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] < 10 && matrix[i][j] > -10) {
                    System.out.print(" ");
                }//www .  j av  a 2  s  . com
                if (matrix[i][j] < 100 && matrix[i][j] > -100) {
                    System.out.print(" ");
                }
                if (matrix[i][j] >= 0) {
                    System.out.print(" ");
                }
                System.out.print(" " + matrix[i][j]);
            }
            System.out.println();
        }
    }

    public static void printMatrix(boolean[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j]) {
                    System.out.print("1");
                } else {
                    System.out.print("0");
                }
            }
            System.out.println();
        }
    }

    public static void printMatrix(char[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                System.out.print(matrix[i][j]);
            }
            System.out.println();
        }
    }
}

Related

  1. printMatrix(int M, int N, double mat[][])
  2. printMatrix(int m, int n, double[][] a)
  3. printMatrix(int matrix[][])
  4. printMatrix(int[] array, String format, int width)
  5. printMatrix(int[][] M)
  6. printMatrix(int[][] s)
  7. printMatrix(int[][] target)
  8. printMatrix(Object[][] matrix)
  9. printMatrix(Object[][] matrix)