Answers for "calculate pi java"

1

calculate pi in java

private static double calcPi(final int iterations){
        double x;
        double y;
        int successCount = 0;
        for (int i = 0; i <= iterations; i++){
            x = Math.random();
            y = Math.random();
            if ((Math.pow(x, 2) + Math.pow(y, 2)) <= 1){
                successCount++;
            }
        }
	    return (double) (4 * successCount) / iterations;
    }
Posted by: Guest on September-08-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language