import java.util.*; import java.io.*; import java.math.*; public class pi_estimator { /** * @param args */ public static void main(String[] args) { long z=0, n=1000000; double x, y, pi; Random rnd = new Random(); for (long i=0; i < n; ++i) { x = rnd.nextDouble(); y = rnd.nextDouble(); if (Math.sqrt(x*x + y*y) <= 1) z++; } pi = 4.0*z/n; System.out.println("Pi is estimated to be " + pi); } }