Skip to content

Instantly share code, notes, and snippets.

@maf946
Last active October 1, 2020 14:19
Show Gist options
  • Save maf946/089f0c20c93006c23fa63166e7538824 to your computer and use it in GitHub Desktop.
Save maf946/089f0c20c93006c23fa63166e7538824 to your computer and use it in GitHub Desktop.
// This is the player's hand.
// Write your code below here.
// Replace this line with your code
// This is the dealer's hand.
int cardD1 = (int) (Math.random() * (11 - 1 + 1)) + 1;
int cardD2 = (int) (Math.random() * (11 - 1 + 1)) + 1;
int dHand = cardD1 + cardD2;
while (dHand < 17) {
dHand += (int) (Math.random() * (11 - 1 + 1)) +1; // get next card; casting
}
System.out.println("Dealer's hand: " + dHand);
// Decide the winner
if((dHand <= 21 && dHand > pHand) || pHand > 21 || dHand == pHand) {
System.out.println(dHand + " Dealer wins");
} else {
System.out.println(pHand + " You win!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment