匿名 #7769(2008/10/10 13:29 GMT) [ Java ] Rating0/0=0.00
遅い、精度が低い
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); } }
Rating0/0=0.00-0+
1 reply [ reply ]
匿名
#7769()
[
Java
]
Rating0/0=0.00
Rating0/0=0.00-0+
1 reply [ reply ]