Random numbers and an Out of Bounds exception teaming up to annoy me.
I'm writing a program to test the Monty Hall problem. I have most of it figured out (though I'm sure I made it more difficult that I had to), I'm just getting an Out of Bounds Exception and I'm not sure why.
The code's kinda long so I'll just post the part bothering me.
a and b should randomly be 0, 1 or 2. Then I'm trying to add 1 to the number in doors[a] and doors[b], to tell me where the car is and which door the person chose.
public class Main
public static void main(String args)
for (int i=0; i<100000; i++)
//put car behind random door
randomNum = new Random();
int a = (randomNum.nextInt())%3;
doors = new int;
for (int j=0; j<3; j++)
//player chooses random door
int b = (randomNum.nextInt())%3;
If you don't know what the Monty Hall problem is, it's on Wikipedia, but it shouldn't really be necessary.