日期:2014-05-17  浏览次数:20723 次

Java洗牌发牌
java洗牌发牌

01 import java.util.*;  
02 public class Main {  
03  
04 /**  
05 * @param args the command line arguments  
06 */ 
07 static int numbersOfPlayers = 4;  
08 static int numbersOfHandCard = 13;  
09 public static void main(String[] args) {  
10 // TODO code application logic here  
11 String[] player = {"小王","小张","小赵","小白"};  
12 String sentence = "的手牌是:";  
13 String[] huase = {"?","?","?","?"};  
14 String[] paiValue ={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};  
15  
16 List deak = new ArrayList();  
17 for(int i = 0;i < 4;i++){  
18 for(int j = 0; j < 13;j++)  
19 {  
20 deak.add(huase[i]+paiValue[j]);  
21 }  
22 }  
23 Collections.shuffle(deak);  
24  
25 for(int i = 0;i < numbersOfPlayers;i++){  
26 System.out.print(player[i]+sentence);  
27 System.out.println(dealHand(deak, numbersOfHandCard));  
28 }  
29 }  
30  
31 public static List dealHand(List Ls,int n){  
32 int sizePai = Ls.size();  
33 List handView = Ls.subList(sizePai - n, sizePai);  
34 List hand = new ArrayList(handView);  
35 handView.clear();  
36 return hand;  
37 }  
38  
39 } 


------解决方案--------------------
坐等 ,输出啥?