Here you can find the source of matrixToString(double[][] matrix, int digit, String[] names)
public static String matrixToString(double[][] matrix, int digit, String[] names)
//package com.java2s; //License from project: Open Source License public class Main { public static String matrixToString(double[][] matrix, int digit, String[] names) { StringBuilder output = new StringBuilder(); for (int i = 0; i < matrix.length; i++) { if (names != null) output.append(names[i]).append("\t"); output.append(arrayToString(matrix[i], digit)).append("\n"); }//from w w w.j a v a 2s . co m return output.toString(); } public static String arrayToString(int[] array) { StringBuilder output = new StringBuilder(); for (int i = 0; i < array.length - 1; i++) { output.append(String.format("%d\t", array[i])); } output.append(String.format("%d", array[array.length - 1])); return output.toString(); } public static String arrayToString(double[] array) { StringBuilder output = new StringBuilder(); for (int i = 0; i < array.length - 1; i++) { output.append(String.format("%.2f\t", array[i])); } output.append(String.format("%.2f", array[array.length - 1])); return output.toString(); } public static String arrayToString(double[] array, String format) { StringBuilder output = new StringBuilder(); for (int i = 0; i < array.length - 1; i++) { output.append(String.format(format + "\t", array[i])); } output.append(String.format(format, array[array.length - 1])); return output.toString(); } public static String arrayToString(double[] array, int digit) { StringBuilder output = new StringBuilder(); for (int i = 0; i < array.length - 1; i++) { output.append(String.format("%." + digit + "f\t", array[i])); } output.append(String.format("%." + digit + "f", array[array.length - 1])); return output.toString(); } }