Java Matrix to String matrixToString(int[][] m)

Here you can find the source of matrixToString(int[][] m)

Description

Creates and returns a formatted string represenation of the input matrix m

License

Open Source License

Parameter

Parameter Description
m A matrix to get its formatted string representation

Return

A formatted string of the input matrix: [[a, b, c], [d, e, f]]

Declaration

public static String matrixToString(int[][] m) 

Method Source Code

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

public class Main {
    /**//from   www . j  a  v  a  2  s .  c  o m
     * Creates and returns a formatted string represenation of the input matrix m
     * @param m A matrix to get its formatted string representation
     * @return A formatted string of the input matrix: [[a, b, c], [d, e, f]]
     */
    public static String matrixToString(int[][] m) {
        String str = "";

        for (int i = 0; i < m.length; i++) {
            str += ((str.length() > 0) ? ",\n" : "") + "[";

            for (int j = 0; j < m[0].length; j++)
                str += m[i][j] + ((j < m[0].length - 1) ? ", " : "");

            str += "]";
        }
        return str;
    }
}

Related

  1. formatTable(String[][] table)
  2. matrix2string(int[][] matrix)
  3. matrix_toString(int[][] matrix)
  4. matrixToString(double[][] matrix, int digit, String[] names)
  5. matrixToString(float[][][] matrix)
  6. matrixToString(int[][] matrix, String sep)
  7. matrixToString(String[][] m)
  8. toString(double[][] A)
  9. toString(double[][] array)