Skip to content

Instantly share code, notes, and snippets.

@applemango
Created April 14, 2022 09:21
Show Gist options
  • Save applemango/5879a49242eefe790f7a98104aac75ec to your computer and use it in GitHub Desktop.
Save applemango/5879a49242eefe790f7a98104aac75ec to your computer and use it in GitHub Desktop.
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