1 import java.util.ArrayList;
2 import java.util.Collections;
3 import java.util.Random;
4
5 public class Poker {
6 public static void main(String[] args) {
7 //1,先装54张牌
8 ArrayList<String> poker = new ArrayList<>();
9 String[] color ={"❤","♦","♠","♣"};
10 String[] numbers ={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
11 poker.add("RedJoker");
12 poker.add("BlackJoker");
13 for (String s : color) {
14 for (String number : numbers) {
15 poker.add(s+number);
16 }
17 }
18 //2,对扑克牌进行洗牌
19 Collections.shuffle(poker);
20
21 //3,发牌
22 ArrayList<String> player01 =new ArrayList<>();
23 ArrayList<String> player02 =new ArrayList<>();
24 ArrayList<String> player03 =new ArrayList<>();
25 ArrayList<String> dipai =new ArrayList<>();
26 for (int i = 0; i < poker.size(); i++) {
27 String p = poker.get(i);
28 if(i>50){
29 dipai.add(p);
30 }else if(i%3==0){
31 player01.add(p);
32 }else if(i%3==1){
33 player02.add(p);
34 }else if(i%3==2){
35 player03.add(p);
36 }
37 }
38 //4,随机一个地主
39 Random r = new Random();
40 int i= r.nextInt(3);
41 for (int j = 0; j <dipai.size() ; j++) {
42 String di = dipai.get(j);
43 if(i==0){
44 player01.add(di);
45 }else if(i==1){
46 player02.add(di);
47 }else if(i==2){
48 player03.add(di);
49 }
50 }
51 //5,看牌
52 String[] player = {"吴彦祖","周润发","周星驰"};
53 System.out.println("地主是"+player[i]);
54 System.out.println(player[0]+player01+",牌数为:"+player01.size());
55 System.out.println(player[1]+player02+", 牌数为:"+player02.size());
56 System.out.println(player[2]+player03+",牌数为:"+player03.size());
57 }
58 }
运行代码↓