Created
March 21, 2011 17:54
-
-
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.
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
/* 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