尝试从数组中打印字符串,但它只打印null

时间:2018-01-03 02:55:11

标签: java null

我有一个课程可以创建一副牌。这是代码: 公共类卡

public class Cards
{
    int Suit;
    int Card;
    int sizeOfHand = 5;
    int numPlayers = 5; //determined by user
    String[] suits = {"diamonds", "clubs", "hearts", "spades"};

    String[] values = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
    boolean[][] chosen;
    String[] deck = new String[52];
    boolean done = false;

    public void card()
    {
    while(!done)
    {
        chosen = new boolean[13][4];

        for(int j = 0; j < 52; j++)
        {
            do
            {
                Suit = (int)(Math.random() * suits.length);
                Card = (int)(Math.random() * values.length);
            }
            while(chosen[Card][Suit]);

            chosen[Card][Suit] = true; //makes sure card is not picked twice

            deck[j] = values[Card] + suits[Suit]; //sets each of the 52 values of deck to a "card"

            done = true; //if it has picked every card
        }
    }
}
}

另一个应该给这些卡片中的“玩家”8的课程,这里是代码:

public class Player
{   
public static void main(String args[])
{
    String name;
    int balance;
    boolean cont = true;

    String[] hand = new String[8];

    Cards c = new Cards();

    //set i = to what ever number player you are on
    for(int i = 0; i < 7; i++)
    {
        hand[i] = c.deck[i];
    }

    System.out.println(Arrays.toString(hand));
    }
}

当我尝试打印玩家的手时,它会打印; [null,null,null,null,null,null,null,null]而不是玩家拥有的实际牌。有人知道为什么会这样吗?

0 个答案:

没有答案