Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created November 29, 2019 21:28
Show Gist options
  • Save gitaficionado/abbaccd003a4f7860a4f575193b314a5 to your computer and use it in GitHub Desktop.
Save gitaficionado/abbaccd003a4f7860a4f575193b314a5 to your computer and use it in GitHub Desktop.
(Game: chance of winning at craps) Revise Exercise 6.30 to run it 10,000 times and display the number of winning games
public class ChanceAtWinningGraps_06_32 {
public static void main(String[] args) {
int winCount = __;
for (int i = ___; i < 10000; i++) {
int dice = _________();
if (dice == ____ || dice == ___) {
_________________++;
}
else if (dice == 2 || dice == 3 || dice == 12) {
//System.out.println("You lose");
}
else {
int point = _____;
//System.out.println("point is " + point);
do {
dice = ________();
} while (dice != 7 && dice != point);
if (dice == 7) {
//System.out.println("You lose");
}
else {
winCount++;
}
}
}
System.out.println(winCount);
}
// Get a dice
public static int getDice() {
int i1 = 1 + (int)(Math.random() * 6);
int i2 = 1 + (int)(Math.random() * 6);
// System.out.println("You rolled " + i1 + " + " + i2 + " = " + (i1 + i2));
return i1 + i2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment