Skip to content

Instantly share code, notes, and snippets.

@amadamala
Created March 21, 2011 17:54
Show Gist options
  • Save amadamala/879868 to your computer and use it in GitHub Desktop.
Save amadamala/879868 to your computer and use it in GitHub Desktop.
Design a class to represent a deck of cards, and implement a shuffle method for the deck of cards.
/* Design a class to represent a deck of cards, and implement a
shuffle method for the deck of cards. http://goo.gl/T4Bk9 */
import java.util.Arrays;
import java.util.Random;
public class DeckOfCards {
public static String deck = "23456789TJQKA";
public static int numOfShuffles = 13;
public static void main(String[] args) {
char[] d = new char[13];
d = deck.toCharArray();
Random rand = new Random();
int n = 13, randnum;
for(int i = 0; i < numOfShuffles; i++) {
randnum = rand.nextInt(n);
//System.out.println(randnum);
char temp = d[0];
d[0] = d[randnum];
d[randnum] = temp;
}
System.out.println(Arrays.toString(d));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment