Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 21点游戏中的For循环错误_Loops_For Loop - Fatal编程技术网

Loops 21点游戏中的For循环错误

Loops 21点游戏中的For循环错误,loops,for-loop,Loops,For Loop,有人能给我解释一下为什么我在第20行出错吗 package play; 导入java.security.SecureRandom public Deck() { deck = new Card[52]; //52 cards in a deck int cardsUsed = 0; for(int s = 0; s < 4; s++); //suit of card { for(int n = 1; n <= 13;

有人能给我解释一下为什么我在第20行出错吗

package play;
导入java.security.SecureRandom

public Deck()
{
    deck = new Card[52];        //52 cards in a deck
    int cardsUsed = 0;

    for(int s = 0; s < 4; s++); //suit of card
    {
        for(int n = 1; n <= 13; n++)        //number of card
        {
            deck[cardsUsed] = new Card(n, s);   **error is "s" on this line**

            cardsUsed++;
        }   
    }
    cardsInDeck = 0;
}

public void shuffle()
{
    for(int shuff = 51; shuff > 0; shuff--)
    {
        //select random # between 0 and 51
        int second = random.nextInt(52);

        //swap current card with new random card
        Card temp = deck[shuff];
        deck[shuff] = deck[second];
        deck[second] = temp;

    }
    cardsInDeck = 0;
}

public int remainingCards()
{
    //number of cards decrease as they are dealt. 
    return 52 - cardsInDeck;
}

public Card dealCard()
{
    //deals a card from the deck
    if(cardsInDeck == 52)
        shuffle();
    cardsInDeck++;
    return deck[cardsInDeck - 1];
}
公务舱甲板 { private int cardsInDeck;//牌组中剩余的牌数 私人卡[]牌组;//牌组中的卡 私有静态最终SecureRandom random=新SecureRandom

public Deck()
{
    deck = new Card[52];        //52 cards in a deck
    int cardsUsed = 0;

    for(int s = 0; s < 4; s++); //suit of card
    {
        for(int n = 1; n <= 13; n++)        //number of card
        {
            deck[cardsUsed] = new Card(n, s);   **error is "s" on this line**

            cardsUsed++;
        }   
    }
    cardsInDeck = 0;
}

public void shuffle()
{
    for(int shuff = 51; shuff > 0; shuff--)
    {
        //select random # between 0 and 51
        int second = random.nextInt(52);

        //swap current card with new random card
        Card temp = deck[shuff];
        deck[shuff] = deck[second];
        deck[second] = temp;

    }
    cardsInDeck = 0;
}

public int remainingCards()
{
    //number of cards decrease as they are dealt. 
    return 52 - cardsInDeck;
}

public Card dealCard()
{
    //deals a card from the deck
    if(cardsInDeck == 52)
        shuffle();
    cardsInDeck++;
    return deck[cardsInDeck - 1];
}
}//末级甲板

仔细看看

for(int s = 0; s < 4; s++); //suit of card
{
    ...
}
这个分号导致变量s没有在下面的块中声明,这就是为什么在下面几行出现错误的原因