Skip to content

Instantly share code, notes, and snippets.

@ImDevinC
Created March 16, 2015 13:36
Show Gist options
  • Save ImDevinC/77ff205e4d7d4664b3cd to your computer and use it in GitHub Desktop.
Save ImDevinC/77ff205e4d7d4664b3cd to your computer and use it in GitHub Desktop.
Random r = new Random();
int selectedCard = r.nextInt(52) + 1; // 51 is the maximum, 1 is the minimum
String suit = "";
String card = "";
int cardNum = 0;
if (selectedCard <= 13) {
suit = "Hearts";
} else if (selectedcard <= 26) {
suit = "Diamonds";
cardNum -= 13;
} else if (selectedCard <= 39) {
suit = "Clubs";
cardNum -= 26;
} else {
suit = "Spades";
cardNum -= 39;
}
switch (cardNum) {
case 1:
card = "Ace";
case 11:
card = "Jack";
case 12:
card = "Queen";
case 13:
card = "King";
default:
card = String.valueOf(cardNum);
}
System.out.println("You drew a " + card);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment