简体   繁体   中英

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). The winner is the one with the Ace of Spades card.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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