所以我是编程初学者,我在课堂上有一个项目,要求我打一手桥牌并将其分发给四名玩家。其中一项任务要求我打印出一副洗牌的牌,但是,当我尝试打印它时,它输出 52 个空语句而不是洗牌的牌。有人可以帮我解决这个问题吗?谢谢。
import java.util.*;
public class Card {
public static String[] SUITS = {"Clubs","Diamonds","Hearts","Spades"};
public static String[] RANKS = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
public static String[]deck = new String[52];
public static String[] createDeck() { // initializes and creates deck
for(int i = 0; i < RANKS.length ; i++) {
for(int j = 0; j < SUITS.length ; j++) {
deck[SUITS.length * i + j] = RANKS[i] + " of " + SUITS[j];
}
}
return deck;
}
public static void shuffleDeck(String[]deck) { //shuffles deck created from array
int n = deck.length;
for (int i = 0; i < n; i++) {
int r = i + (int)(Math.random() * (n-i));
String temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
System.out.println(deck[i]);
}
}
public static void main(String[] args) {
Card.shuffleDeck(deck);
}
catspeake
相关分类