有人可以向我解释为什么我在第20行收到错误?
package play;
import java.security.SecureRandom;
公共课甲板 { private int cardsInDeck; //卡片中留下的卡片数量 私人卡[]甲板; //牌组中的牌 private static final SecureRandom random = new 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];
}
} //结束课甲板
答案 0 :(得分:0)
仔细看看
for(int s = 0; s < 4; s++); //suit of card
{
...
}
这个分号导致变量s
未在下面的块中声明,这就是错误发生在下面几行的原因。