我试图输出赢取掷骰子游戏的概率。
每次我尝试运行程序时,输出都是空的。
这是代码:
import java.util.Random;
public class CrapsGame {
public static void main(String[] args) {
int diceOne = 0; //declare the following variables as an integer
int diceTwo = 0;
int tot = 0;
int tot2 = 0;
int point = 0;
int win = 0;
int loss = 0;
double prob;
Random randomNum = new Random(); // gives randomNum a random value
for (int counter = 1; counter <= 10000; counter++) { // the loop will run up to 10,000 times
diceOne = randomNum.nextInt(6) + 1; //gives a random value to the first dice
diceTwo = randomNum.nextInt(6) + 1; //gives a random value to the first dice
tot = diceOne + diceTwo; //calculates the first total
if (tot == 7 || tot == 11) //if sum equaled 7 or 11
{
win = win + 1;
} else if (tot == 2 || tot == 3 || tot == 12) //if sum equales to 2, 3, or 12
{
loss = loss + 1;
} else
{
point = tot;
do
{
diceOne = randomNum.nextInt(6) + 1; //do loop setting dice1 and 2 equaled to a random number
diceTwo = randomNum.nextInt(6) + 1;
tot2 = diceOne + diceTwo;
} while (tot2 != 7 || tot2 != point); //while sum2 is not equal to 7 or point
if (tot2 == 7) //if sum2 equal 7
{
loss = loss + 1;
} else if (tot2 == point) //else if sum2 equal to point
{
win = win + 1;
}
prob = win / (win + loss);
System.out.println(prob);
}
}
}
}