Advertisement
hocikto19

PSFYZ1

Feb 16th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. package mcvypocetpi;
  2. import java.util.Random;
  3.  
  4. public class MCVypocetPi {
  5.  
  6.     public static void main(String[] args) {
  7.         Random rand = new Random();
  8.         int pocitadloZasahov=0;
  9.         int pocetCyklov=Integer.MAX_VALUE;
  10.         for(int i=0; i<pocetCyklov; i++){
  11.             double x = rand.nextDouble();
  12.             double y = rand.nextDouble();
  13.             if(Math.sqrt(x*x+y*y)<=1){
  14.                 pocitadloZasahov++;
  15.             }
  16.         }
  17.         double objemStvrtkruhu = (double)pocitadloZasahov/pocetCyklov;
  18.         System.out.println(objemStvrtkruhu*4);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement