Java Reference
In-Depth Information
Figure 4
When Does the Needle Fall on a Line?
258
259
Here is the program to carry out the simulation of the needle experiment.
ch06/random2/Needle.java
1 import java.util.Random;
2
3 /**
4This class simulates a needle in the Buffon needle experiment.
5 */
6 public class Needle
7 {
8 /**
9Constructs a needle.
10 */
11 public Needle()
12 {
13 hits = 0;
14 tries = 0;
15 generator = new Random();
16 }
17
18 /**
19Drops the needle on the grid of lines and
20 remembers whether the needle hit a
line.
Search WWH ::




Custom Search