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