Java Utililty Methods Matrix Print

List of utility methods to do Matrix Print

Description

The list of methods to do Matrix Print are organized into topic(s).

Method

voidprintMatrix(double[][] matrix)
print Matrix
for (int i = 0; i < matrix.length; i++) {
    String line = Arrays.toString(matrix[i]);
    line = line.replaceAll(", ", "\t");
    System.out.println(line);
System.out.println();
voidprintMatrix(double[][] matrix)
Debug function for displaying a matrix
int dim = matrix.length;
for (int i = 0; i < dim; i++) {
    for (int j = 0; j < dim; j++) {
        System.out.printf("%5f", matrix[i][j]);
        if (i == j && matrix[i][j] != 0) {
    System.out.println();
...
voidprintMatrix(double[][] sims)
print Matrix
if (sims.length == 0)
    return;
for (int i = 0; i < sims.length; i++) {
    for (int j = 0; j < sims[0].length; j++) {
        System.out.printf("%.2f ", sims[i][j]);
    System.out.println();
StringprintMatrix(final double m[][])
print Matrix
StringBuilder sb = new StringBuilder();
for (int i = 0; i < m.length; ++i) {
    for (int j = 0; j < m[i].length; ++j) {
        if (j > 0) {
            sb.append('\t');
        sb.append(m[i][j]);
    sb.append('\n');
return sb.toString();
voidprintMatrix(float[] array, int rows, int columns)
print Matrix
StringBuilder sb = new StringBuilder();
NumberFormat formatter = new DecimalFormat("#0.00");
IntStream.range(0, columns).forEach(i -> {
    IntStream.range(0, columns)
            .forEach(j -> sb.append(formatter.format(array[i * columns + j])).append(" "));
    sb.append(System.getProperty("line.separator"));
});
System.out.println(sb.toString());
...
voidprintMatrix(int M, int N, double mat[][])
print Matrix
for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++)
        System.out.print(mat[i][j] + " ");
    System.out.println();
voidprintMatrix(int m, int n, double[][] a)
print Matrix
int i, j;
for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++)
        System.out.print("  " + a[i][j]);
    System.out.println();
System.out.println();
voidprintMatrix(int matrix[][])
Prints the provided incidence matrix
System.out.println("{"); 
for (int i = 0; i < matrix.length; i++) { 
    int[] row = matrix[i];
    System.out.print("  { "); 
    for (int j = 0; j < row.length; j++) { 
        if (j == 0)
            System.out.print(row[j]);
        else
...
voidprintMatrix(int[] array, String format, int width)
print Matrix
String[] strings = new String[array.length];
int maxLen = 0;
for (int i = 0; i < array.length; i++) {
    strings[i] = String.format(format, array[i]);
    maxLen = Math.max(maxLen, strings[i].length());
for (int ind = 0; ind < strings.length;) {
    StringBuilder builder = new StringBuilder();
...
voidprintMatrix(int[][] M)
print Matrix
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]);
    System.out.println();