1 /**
2 This program simulates the Buffon needle experiment
3 and prints the resulting approximations of pi.
4 */
5 public class NeedleSimulator
6 {
7 public static void main(String[] args)
8 {
9 Needle n = new Needle();
10 final int TRIES1 = 10000;
11 final int TRIES2 = 1000000;
12
13 for (int i = 1; i <= TRIES1; i++)
14 n.drop();
15 System.out.printf("Tries = %d, Tries / Hits = %8.5f\n",
16 TRIES1, (double) n.getTries() / n.getHits());
17
18 for (int i = TRIES1 + 1; i <= TRIES2; i++)
19 n.drop();
20 System.out.printf("Tries = %d, Tries / Hits = %8.5f\n",
21 TRIES2, (double) n.getTries() / n.getHits());
22 }
23 }