以下代码提供了正确的输出,但与我需要的格式不完全相同。
当前代码:
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Deck deck = new Deck();
Card C;
System.out.println(deck.getTotalCards());
System.out.print("Number of players: ");
int players = scan.nextInt();
System.out.print("Number of cards: ");
int cards = scan.nextInt();
for(int k=0; k<players; ++k)
{
for(int i =0; i<cards; i++)
{
C = deck.drawFromDeck();
System.out.println("Player "+(k+1) + ": " + C.toString());
}
}
scan.close();
}
这提供了以下输出:
51 // number of cards in deck
Number of players: 3 //3 - entered by user
Number of cards: 2 // 2- entered by user
Player 1: 4 of Spades
Player 1: Jack of Diamonds
Player 2: 6 of Clubs
Player 2: 2 of Hearts
Player 3: Jack of Clubs
Player 3: 8 of Diamonds
期望的输出:
51
Number of players: 3 //3 - entered by user
Number of cards: 2 // 2- entered by user
Player 1: 4 of Spades, Jack of Diamonds
Player 2: 6 of Clubs, 2 of Hearts
Player 3: Jack of Clubs, 8 of Diamonds
如何更改我的 for 循环以反映我想要的输出。