【課題】
import java.io.*;
public class Approx {
public static void main (String[] args) {
int i, n=1000000, k=0; double x, y, ds, ap; PrintWriter fo; long tb, te;
try {
fo=new PrintWriter(
new BufferedWriter(
new FileWriter(
args[0])));
tb=System.currentTimeMillis();
for (i=0; i<n; i++) {
x=2*Math.random()-1;
y=2*Math.random()-1;
if ((x-1)*(y-1)>1) k++;
}
te=System.currentTimeMillis();
long dm=te-tb;
ds=dm/1000.0;
ap=4.0*k/n;
fo.println(ds+"秒\n"+"近似値 ="+ap);
fo.close();
}
catch(Exception e) {
System.out.println("書き込みエラー: "+e);
}}}
(1)dmでは何を計算しているか。
(2)apを次式で計算した場合の格値とその理由を説明せよ。
(i)ap=k/n*4.0;
(ii)ap=4*k/n;
【期限】過ぎてます・・・