Forum Comments

5.14 Project E6.22 - Monty Hall Simulation
In Introduction to Java
ultragumgaming27
Apr 02, 2020
import java.util.Scanner; public class MontyHall { public static void main(String[] args) { Scanner in = new Scanner(System.in); Scanner in2 = new Scanner(System.in); int input = 0; int open[] = new int[2]; int car = (int)(3 * Math.random()) + 1; int switchWin = 0; int noSwitchWin = 0; int change = (int) (2 * Math.random()); for (int r = 0; r < 10; r++) { car = (int)(3 * Math.random()) + 1; input = 0; System.out.println("Please select a door: [1] [2] [3]"); input = in.nextInt(); if (input != car) { System.out.println("We open door #" + (6 - car - input) + " and find that there is a goat!"); open[0] = 6 - car - input; open[1] = input; } else { for (int i = 0; i < 3; i++){ if (i != car){ open[0] = i; open[1] = input; } } System.out.println("We open door #" + open[0] + "and find that there is a goat!"); } if (change == 1) { input = 6 - open[1] - open[0]; if (input == car) { System.out.println("We open door #" + input + " and reveal that you have won the CAR! Congrats!"); switchWin++; } else { System.out.println("We open door #" + input + " and reveal that you have won a GOAT! Better luck next time!"); } } else { if (input == car) { System.out.println("We open door #" + input + " and reveal that you have won the CAR! Congrats!"); noSwitchWin++; } else { System.out.println("We open door #" + input + " and reveal that you have won a GOAT! Better luck next time!"); } } System.out.println("Simulation Rebooting..."); } System.out.println("Switching won: " + switchWin + " times and not switching won: " + noSwitchWin + " times"); } }
0
0
4-1 What is data structure? Is an array just a collection of the same type of variables?
In ACSL Contest Prep
ultragumgaming27
Feb 24, 2019
2006-2007 1) 4 2) ?? 2009-2010 1) 6 2) ???
0
0
7-1 Why prefix or post fix notations are used in computers?
In ACSL Contest Prep
8.1 What are bit strings? What do we use bit strings for?
In ACSL Contest Prep
3.1 What is a function? What is a recursive function?
In ACSL Contest Prep
ultragumgaming27
Dec 09, 2018
1) Seventy Nien 2) six 3) ???
0
0
C9 Arrays and Loops in Actions
In Introduction to Java
ultragumgaming27
Nov 11, 2018
r7.10 a) error bounds b)no = aftter int
0
0
u
ultragumgaming27
More actions