Created
January 9, 2024 14:58
-
-
Save Ranzeplay/c4b9ad2485626fc1acf0abd96920371f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Random; | |
| public class Main { | |
| public static void main(String[] args) { | |
| for(var a = 0; a < 100; a++) { | |
| int count = 0; | |
| for (var i = 0; i < 20000; i++) { | |
| var x = new Random().doubles(0, 2).findFirst().getAsDouble(); | |
| var y = new Random().doubles(0, 2).findFirst().getAsDouble(); | |
| if ((x - 1) * (x - 1) + (y - 1) * (y - 1) <= 1) { | |
| count++; | |
| } | |
| } | |
| System.out.println("Approx PI value: " + 4 * count / (double)20000); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment