Loops 21点游戏中的For循环错误
有人能给我解释一下为什么我在第20行出错吗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;
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没有在下面的块中声明,这就是为什么在下面几行出现错误的原因