fork download
  1. import java.io.*;
  2.  
  3. class Main
  4. {
  5. public static void main(String args[]) {
  6. int n = 10000000;
  7. double s = 0;
  8. for(int i = 0; i < n; i++) {
  9. double x = Math.random();
  10. double y = Math.random();
  11. if((x*x+y*y) < 1.0) {
  12. s += 1.0;
  13. }
  14. }
  15. System.out.println(4.0*s/n);
  16. }
  17. }
Success #stdin #stdout 1.57s 380224KB
stdin
Standard input is empty
stdout
3.1418796