I made this card shuffler that creates and randomizes a deck of 52. The only problem is that there is no restrictions against randomizing a duplicate card. I was thinking of storing the instance of the card[] into a 2d array like deck[][]. Then the program could check to see if the newly randomized card already exists. The only problem is... I don't really know how to do that. If anyone has a good idea, I would appreciate it.
import java.util.Arrays;
public class cardShuffle {
public static void main(String[] args) {
String[] card = new String[2];
String[] suits = {"♢", "♥", "♤", "♧"};
String[] faces = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Joker", "Queen", "King"};
//Randomizes and prints a deck of 52 cards
for(int i = 0; i < 52; i++){
card[0] = suits[(int) (Math.random() * 4)];//Picks a random suit
card[1] = faces[(int) (Math.random() * 13)];//Picks a random face value
System.out.println(Arrays.toString(card));//Prints the randomized card
}
}
}
Aucun commentaire:
Enregistrer un commentaire