Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mcvypocetpi;
- import java.util.Random;
- public class MCVypocetPi {
- public static void main(String[] args) {
- Random rand = new Random();
- int pocitadloZasahov=0;
- int pocetCyklov=Integer.MAX_VALUE;
- for(int i=0; i<pocetCyklov; i++){
- double x = rand.nextDouble();
- double y = rand.nextDouble();
- if(Math.sqrt(x*x+y*y)<=1){
- pocitadloZasahov++;
- }
- }
- double objemStvrtkruhu = (double)pocitadloZasahov/pocetCyklov;
- System.out.println(objemStvrtkruhu*4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement