Add tags

Add tags to the following comment
遅い、精度が低い
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import java.util.Random;
/**
 * 教科書的なモンテカルロ法
 */
public class Pi {
    public static void main(String args[]) {
    Random r= new Random();
    int m=1000000;
    double j=0;
    for(int i=0;i<m;i++)
        if(Math.hypot(r.nextDouble(),r.nextDouble())<1.0)
          j++;
    System.out.println(4*j/m);
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...