List¸¦ ÀÌ¿ëÇÑ °£´ÜÇÑ Æ÷Ä¿°ÔÀÓ
ListTest3.java
import java.util.*;
public class ListTest3 {
public static void main(String args[]) {
int gamerNum = Integer.parseInt(args[0]);
int cardNum = 5;
//52Àå Ä«µåÇѹú ¸¸µé±â
String[] suit = new String[] {"spade", "heart", "diamond", "club"};
String[] rank = new String[] {"ace","2","3","4","5","6","7","8","9","10","jack","queen","king"};
List deck = new ArrayList();
for (int i=0; i<suit.length; i++) {
for (int j=0; j<rank.length; j++) {
deck.add(rank[j] + " of " + suit[i]);
}
}
Collections.shuffle(deck);
for (int i=0; i<gamerNum; i++){
System.out.println("gamer" + i +":" + dealHand(deck, cardNum));
}
}
public static List dealHand(List deck, int n) {
int deckSize = deck.size();
List handView = deck.subList(deckSize-n, deckSize);
List hand = new ArrayList(handView);
handView.clear();
return hand;
}
}
D:\java\util\after>javac ListTest3.java
D:\java\util\after>java ListTest3 4
gamer0:[6 of spade, 9 of spade, king of spade, 3 of diamond, 6 of club]
gamer1:[3 of club, 4 of spade, queen of club, 2 of club, 7 of diamond]
gamer2:[6 of diamond, 9 of heart, 5 of club, 8 of heart, 7 of spade]
gamer3:[2 of diamond, jack of heart, 4 of heart, ace of spade, queen of diamond]
List¸¦ ÀÌ¿ëÇÑ °£´ÜÇÑ Æ÷Ä¿°ÔÀÓ ¸¸µé±â
jabookÀúÀÚ¸íÇÔ |
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå ÀÛ¼ºÀÚ:Àںϸâ¹ö ±è¿Ï±â |