Last active
October 1, 2020 14:19
-
-
Save maf946/089f0c20c93006c23fa63166e7538824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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