import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;

public class Main {

	public static void main(String[] args) {
		int n = 1000000;
		double[] a = new double[n];
		for(int i=0;i<n;i++) {
			a[i] = Math.random();
		}
//		format1(n,a);
//		format2(n,a);
//		format3(n,a);
		format4(n,a);
	}
	
	public static void format1(int n,double[] a) {
		try {
			PrintWriter pw = new PrintWriter(new File("out1.txt"));
			long stime = System.nanoTime();
			for(int i=0;i<n;i++) {
				pw.printf("%.7f\n", a[i]);
			}
			pw.flush();
			pw.close();
			System.out.println((System.nanoTime() - stime) / 1000000 + " ms");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static void format2(int n,double[] a) {
		try {
			PrintWriter pw = new PrintWriter(new File("out2.txt"));
			long stime = System.nanoTime();
			for(int i=0;i<n;i++) {
				pw.println(String.format("%.7f", a[i]));
			}
			pw.flush();
			pw.close();
			System.out.println((System.nanoTime() - stime) / 1000000 + " ms");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static void format3(int n,double[] a) {

		DecimalFormat df = new DecimalFormat("0.0000000");
		try {
			PrintWriter pw = new PrintWriter(new File("out3.txt"));
			long stime = System.nanoTime();
			for(int i=0;i<n;i++) {
				pw.printf(df.format(a[i]));
			}
			pw.flush();
			pw.close();
			System.out.println((System.nanoTime() - stime) / 1000000 + " ms");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static void format4(int n,double[] a) {
		try {
			PrintWriter pw = new PrintWriter(new File("out4.txt"));
			long stime = System.nanoTime();
			for(int i=0;i<n;i++) {
				pw.printf(dtos(a[i],7));
			}
			pw.flush();
			pw.close();
			System.out.println((System.nanoTime() - stime) / 1000000 + " ms");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	// http://q...content-available-to-author-only...a.com/p_shiki37/items/65c18f88f4d24b2c528b#comment-0b10eebdffb1991f3eb9
	public static String dtos(double x, int n) {
		StringBuilder sb = new StringBuilder();
		if (x < 0) {
			sb.append('-');
			x = -x;
		}
		x += Math.pow(10, -n) / 2;
		// if(x < 0){ x = 0; }
		sb.append((long) x);
		sb.append(".");
		x -= (long) x;
		for (int i = 0; i < n; i++) {
			x *= 10;
			sb.append((int) x);
			x -= (int) x;
		}
		return sb.toString();
	}
}
