Draxion

2 Envelope Paradox

May 28th, 2020
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. public class HelloWorld{
  2.  
  3.      public static void main(String []args){
  4.         int i = 0;
  5.         int total = 0;
  6.         for (i = 0; i < 1000000; i++) {
  7.             int current = (int)Math.ceil(Math.random()*2.0)*100; //Handed envelope
  8.             int swap = 200;
  9.             if (swap == current)
  10.                 swap = 100;
  11.            
  12.             total += swap;
  13.         }
  14.        
  15.         System.out.println(total + " money earned in " + i + " trials for an average earning of " + (double)total/(double)i);
  16.      }
  17. }
Add Comment
Please, Sign In to add comment