简体   繁体   English

程序不打印任何东西?

[英]Program not printing anything ?

I am trying to write a code in which I construct a 52 card pile, then deal the cards out to n number of players (it is possible for some players to have an extra card).我正在尝试编写一个代码,在其中构建 52 张牌堆,然后将这些牌分发给 n 名玩家(某些玩家可能会有一张额外的牌)。 The winner is the one with the Ace of Spades card.获胜者是拥有黑桃 A 牌的人。

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!");
      }
    }

  }
}

When i try to run it with the command "java CardGame 5" the program runs but nothing is printed.当我尝试使用命令“java CardGame 5”运行它时,程序运行但没有打印任何内容。 Can anyone help ?任何人都可以帮忙吗? Thanks !谢谢 !

Change改变

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

to:到:

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

Since the index is zero based.由于索引是基于零的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM