1 private static double calcPi(final int iterations){
2 double x;
3 double y;
4 int successCount = 0;
5 for (int i = 0; i <= iterations; i++){
6 x = Math.random();
7 y = Math.random();
8 if ((Math.pow(x, 2) + Math.pow(y, 2)) <= 1){
9 successCount++;
10 }
11 }
12 return (double) (4 * successCount) / iterations;
13 }