Here's a problem implemented in object-oriented style: 

-bash-4.1$ pico -w Buffon.java
-bash-4.1$ javac Buffon.java
-bash-4.1$ java Buffon 1000
3.194888178913738
-bash-4.1$ java Buffon 10000
3.115264797507788
-bash-4.1$ java Buffon 100000
3.1363693388533433
-bash-4.1$ java Buffon 1000000
3.135061588284902
-bash-4.1$ java Buffon 1000000
3.1349239937677713
-bash-4.1$ java Buffon 1000000
3.139569565012637
-bash-4.1$ java Buffon 10000000
3.1448044057451803
-bash-4.1$ java Buffon 10000000
3.142176906445139
-bash-4.1$ java Buffon 100000000
3.1414331312187613
-bash-4.1$ cat Buffon.java
class Buffon {
    public static void main(String[] args) {
        Needle n = new Needle();
        int tries = Integer.parseInt(args[0]);
        for (int i = 0; i < tries; i++) {
            n.drop();
        }
        System.out.println((double) n.tries / n.hits);
    }
}

class Needle {
    int hits, tries; // by default: 0
    void drop() {
        double angle = Math.random() * Math.PI; // why not 2 * Math.PI?
        double y = Math.random() * 2;
        double span = Math.sin(angle) + y;
        if (y == 0 || span >= 2)
            this.hits += 1;
        this.tries += 1;
    }
}

-bash-4.1$

You can create an array of 100 needles. 

Throw them all once (or 100 times) and then take the average. 

Remember: you need to be able to solve a problem like this not memorize my solution. 

Just knowing ahead what problem you might receive on exam is of great help. 

The solution is offered here to encourage you find one of your own. 

Trying to memorize solutions is not a good idea. 

Good luck tomorrow!

--