Advertisement
calcpage

C6X12_DartSim.java

Jan 31st, 2012
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.55 KB | None | 0 0
  1. /*
  2. DartSim.java        MrG     2012.0131
  3. purpose:    estimate pi via monte carlo simulation
  4. required files: DartSim.java            main class
  5.         Dart.java           derived class
  6. translator: javac DartSim.java
  7. interpreter:    java DartSim trials
  8. */
  9. public class DartSim
  10. {
  11.     public static void main(String[] args)
  12.     {
  13.         int trials = Integer.parseInt(args[0]);
  14.         Dart myDart = new Dart();
  15.         for(int k=1; k<=trials; k++)
  16.         {
  17.             myDart.toss();
  18.             System.out.print("% done = " + (double)k*100/trials);
  19.             System.out.println("\tpi = " + 4.0*myDart.getHits()/myDart.getThrows());
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement