Created
April 14, 2022 09:21
-
-
Save applemango/5879a49242eefe790f7a98104aac75ec to your computer and use it in GitHub Desktop.
This file contains 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
public class pi { | |
public static void main(String[] args) { | |
int n = 30000000; | |
int mc = 0; | |
for (int i = 0; i < n; i++) { | |
double x = Math.random(); | |
double y = Math.random(); | |
mc += (x*x + y*y < 1 )? 1 : 0; | |
} | |
double pi = (double)4*mc/n; | |
System.out.println("pi="+pi); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment