Soo this problem involves me rolling a pair of dice and estimate the probability that the first roll is a losing roll (2, 3, or 12).
output is the count of rolls that were losers (2,3, or 12) and calculated probability (count/N)
public static void main(String [] args){
int N1 = (int) (Math.random()*6 + 1);
int N2 = (int) (Math.random()*6 + 1);
int count = N1 + N2;
for (int i = 0; i<=1; i++)
if (count==2 || count = 3 || count == 12)
I just don’t seem to know what to do get the output…… This is my attempt
It seems that you will want to roll the dice N times (where N is some large number) and count the number of times that it was a loser, correct?
So you will need to store in memory the total number of rolls, and the number of losing rolls. You can store those in
intvariables.An
intvariable can be incremented using the++operator.is equivalent to
You also don’t want to call your
mainfunction a million times, so you can set the upper limit of your loop to the amount of rolls you want to have.To calculate the probability, you will want to use
floats rather thanints – you can cast anintto afloatlike this:Finally, if you want to see your output via standard out, use
System.out.println(). The argument to theprintln()function should be whatever you want to output.Since this sounds like homework, I’m avoiding writing much code for now. Let me know if it isn’t.