Buffon needle(java and matlab)

 

 
java code

 

/****************************************************************** Java Applet buff.java March 1998 - Michael J. Hurben This applet provides a _simulation_ of the famous Buffon's Needle experiment. Buffon's Needle is a Monte Carlo simulation for the determination of the value of pi. ******************************************************************/ import java.applet.*; import java.awt.*; public class buff extends Applet implements Runnable { Dimension offDimension, d; // Variables used to create an Image offImage; // offscreen image via the update() Graphics offGraphics; // method, to reduce flicker int needleLength = 20; int numRows = 10; int xBorder = 15; // Basic layout variables int yBorder = 45; int margin = 50; int tableHeight = needleLength*numRows; // int tableWidth = 200; // Define size of table int tableXcorner = xBorder; // where needles are thrown int tableYcorner = yBorder; // int barWidth =

你可能感兴趣的:(Buffon needle(java and matlab))