Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HelloWorld{
- public static void main(String []args){
- int i = 0;
- int wins = 0;
- for (i = 0; i < 1000000; i++) {
- int winner = (int)Math.ceil(Math.random()*3.0); //Winning choice
- int choice = (int)Math.ceil(Math.random()*3); //Initial Pick
- int open = (int)Math.ceil(Math.random()*3); //Door to open
- while (choice == open || winner == open) { //Making sure the open door is not the winner and the picked door
- open = (int)Math.ceil(Math.random()*3);
- }
- int swap = 1;
- while (choice == swap || swap == open) { //Picks the remaining door`
- swap++;
- }
- if (swap == winner)
- wins++;
- }
- System.out.println(wins + " swaps won out of " + i + " trials for a win percentage of " + (double)wins/(double)i);
- }
- }
Add Comment
Please, Sign In to add comment