Java Matrix Print printMatrix(double[] a, String label)

Here you can find the source of printMatrix(double[] a, String label)

Description

Print a vector for debugging purposes.

License

Open Source License

Parameter

Parameter Description
a Vector to print
label Label to print as a header

Declaration

public static void printMatrix(double[] a, String label) 

Method Source Code

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

public class Main {
    /**//  w w  w.  j a  v a  2 s  .c  om
     * Print a vector for debugging purposes.
     * 
     * @param a Vector to print
     * @param label Label to print as a header
     */
    public static void printMatrix(double[] a, String label) {
        int count;

        System.out.println("\n\t\t" + label + ":");
        count = 0;
        for (int j = 0; j < a.length; j++) {
            if (count > 8) {
                System.out.print("\n           ");
                count = 1;
            }
            System.out.format(" %10.3e", a[j]);
            count++;
        }
        System.out.println();
    }

    /**
     * Print a vector for debugging purposes.
     * 
     * @param a Vector to print
     * @param label Label to print as a header
     */
    public static void printMatrix(int[] a, String label) {
        int count;

        System.out.println("\n\t\t" + label + ":");
        count = 0;
        for (int j = 0; j < a.length; j++) {
            if (count > 17) {
                System.out.print("\n     ");
                count = 1;
            }
            System.out.format(" %4d", a[j]);
            count++;
        }
        System.out.println();
    }

    /**
     * Print a matrix for debugging purposes.
     * 
     * @param a Matrix to print
     * @param label Label to print as a header
     */
    public static void printMatrix(double[][] a, String label) {
        int count;

        System.out.println("\n\t\t" + label + ":");
        for (int i = 0; i < a.length; i++) {
            count = 0;
            for (int j = 0; j < a[i].length; j++) {
                if (count > 8) {
                    System.out.print("\n           ");
                    count = 1;
                }
                System.out.format(" %10.3e", a[i][j]);
                count++;
            }
            System.out.println();
        }
    }
}

Related

  1. print2DIntArray(int[][] nums)
  2. printMatrix(boolean[][] matrix)
  3. printMatrix(byte[][] matrix)
  4. printMatrix(byte[][] matrix, boolean printMatrix)
  5. printMatrix(double data[][])
  6. printMatrix(double[][] matrix)
  7. printMatrix(double[][] matrix)
  8. printMatrix(double[][] matrix)
  9. printMatrix(double[][] matrix)