0
我已經寫了一個甲板類,現在必須洗牌,然後打印出幾隻手來檢查它是如何工作的。然而,它似乎沒有洗牌,而是給出了完全相同的套牌。試圖洗牌「甲板」類,似乎沒有洗牌
public void makeHands() {
Deck deck = new Deck();
Deck shuffled = shuffleDeck (deck);
printDeck (subdeck (shuffled, 0, 4));
printDeck (subdeck (shuffled, 5, 9));
printDeck (subdeck (shuffled, 10, 14));
printDeck (subdeck (shuffled, 15, 19));
}
public static int randomInt (int length, int i) {
double x = Math.random() * length;
int g = (int) x;
return g;
}
public Deck shuffleDeck (Deck deck) {
for (int i=0; i<deck.cards.length; i++) {
int g = randomInt (deck.cards.length, i);
swapCards (i, g);
}
return deck;
}
}
public void swapCards (int first, int swap) {
Card temp = cards[first];
cards[first] = cards[swap];
cards[swap] = temp;
}
功課? ..... – Prescott 2011-04-30 03:00:22