程序不打印任何东西?

时间:2015-11-21 18:27:02

标签: java

我正在尝试编写一个代码,我在其中构建一个52卡堆,然后将卡交给n个玩家(某些玩家可能有额外的卡)。获胜者是带有黑桃卡牌的人。

public class CardGame {
  public static void main(String[] args) { 


    int numofPlayers = Integer.parseInt(args[0]);
    CardPile gameDeck = CardPile.makeFullDeck(); 
    CardPile [] players = new CardPile[numofPlayers];

    for (int i=0;i<numofPlayers;i++) {
      int numofnum = i%numofPlayers;
      players[i] = new CardPile();
    }

    for (int i=0;i<52;i++) {
      int numofnum =i%numofPlayers;
      CardPile curPlayer = players[i%numofPlayers];
      Card nextCard = gameDeck.get(i);
      players[numofnum].addToBottom(nextCard); 

    }
    for (int i=1;i<numofPlayers;i++) {
      if (players[i].find(Suit.SPADES, Value.ACE) != -1) {
        System.out.println("Player" + i + "has won!");
      }
    }

  }
}

当我尝试使用命令&#34; java CardGame 5&#34;程序运行但没有打印。有人可以帮忙吗?谢谢!

1 个答案:

答案 0 :(得分:0)

更改

for (int i=1;i<numofPlayers;i++) {

为:

for (int i=0;i<numofPlayers;i++) {

因为索引是基于零的。