Here you can find the source of printArray(double[] array, String msgBefore, String msgAfter)
public static void printArray(double[] array, String msgBefore, String msgAfter)
//package com.java2s; //License from project: Open Source License public class Main { public static void printArray(double[] array, String msgBefore, String msgAfter) { System.out.print(msgBefore); System.out.print(arrayToString(array)); System.out.print(msgAfter); }//from w w w . j av a 2 s .com public static void printArray(int[] array, String msgBefore, String msgAfter) { System.out.print(msgBefore); System.out.print(arrayToString(array)); System.out.print(msgAfter); } 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(); } }