Skip to content

Instantly share code, notes, and snippets.

@maf946
Last active October 14, 2021 16:14
Show Gist options
  • Save maf946/8c96809a264f2189b6fd5384da951a3b to your computer and use it in GitHub Desktop.
Save maf946/8c96809a264f2189b6fd5384da951a3b to your computer and use it in GitHub Desktop.
package ultrablackjack;
import java.util.Scanner;
/**
*
* @author YOURNAMEHERE
*/
public class UltraBlackjack {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// =================================================
// YOU DON'T NEED TO CHANGE ANYTHING ABOVE THIS LINE
// WRITE CODE HERE TO DETERMINE playerHand
int playerHand = 0; //use this variable to store the player's hand
// =================================================
// YOU DON'T NEED TO CHANGE ANYTHING BELOW THIS LINE
System.out.println("Player's hand: " + playerHand);
// 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 dealerHand = cardD1 + cardD2;
while (dealerHand < 17)
{
dealerHand += (int)(Math.random() * (11 - 1 + 1)) +1; // get next card; casting
}
System.out.println("Dealer's hand: " + dealerHand);
// Decide the winner
if((dealerHand <= 21 && dealerHand > playerHand) || playerHand > 21 || dealerHand == playerHand)
{
System.out.println("Dealer has " + dealerHand + ", so the dealer wins 😢");
}
else
{
System.out.println("You have " + playerHand + ", so you win! 😁");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment