次のコードは正しい出力を提供しますが、私が必要としているのとまったく同じ形式ではありません。
現在のコード:
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ループを変更するにはどうすればよいですか。