package practice.mathematics;

public class MonteCarloPI {

    public static double findPI(int number) {

        double x;
        double y;
        int count = 0;

        for (int i = 0; i < number; i++) {
            x = Math.random();
            y = Math.random();

            if (x * x + y * y < 1.0) {
                count++;
            }
        }

        return (double) count * 4 / number;
    }

    public static void main(String[] args) {
        System.out.println("Pi is " + findPI(5000001));
    }
}

@@ -49,24 +49,533 @@
 eCarloPI %7B%0A%0A
+    public static double findPIv2(int number) %7B%0A        double x;%0A        double y;%0A        int count = 0;%0A        %0A        double increament = 1 / (double) number;%0A        %0A        for (int i = 0; i %3C number; i++) %7B%0A            x = increament * i;%0A            for (int j = 0; j %3C number; j++) %7B%0A                y = increament * j;%0A                if (x * x + y * y %3C 1.0) %7B%0A                    count++;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return (double) count * 4 / (number * number);%0A    %7D%0A%0A
     public s
@@ -608,16 +608,16 @@
 mber) %7B%0A
-
 %0A       
@@ -988,16 +988,19 @@
 rintln(%22
+V1 
 Pi is %22 
@@ -1012,15 +1012,74 @@
 dPI(
-5
+80
 00000
-1
+));%0A        System.out.println(%22V2 Pi is %22 + findPIv2(10000
 ));%0A

Add findPIv2 to MonteCarloPI