1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| package com.itheima.demo04.Test;
import java.util.ArrayList; import java.util.Collections;
public class DouDiZhu { public static void main(String[] args) { ArrayList<String> poker = new ArrayList<>(); String[] colors = {"♠","♥","♣","♦"}; String[] numbers = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"}; poker.add("大王"); poker.add("小王"); for(String number : numbers){ for (String color : colors) { poker.add(color+number); } }
Collections.shuffle(poker);
ArrayList<String> player01 = new ArrayList<>(); ArrayList<String> player02 = new ArrayList<>(); ArrayList<String> player03 = new ArrayList<>(); ArrayList<String> diPai = new ArrayList<>();
for (int i = 0; i < poker.size() ; i++) { String p = poker.get(i); if(i>=51){ diPai.add(p); }else if(i%3==0){ player01.add(p); }else if(i%3==1){ player02.add(p); }else if(i%3==2){ player03.add(p); } }
System.out.println("刘德华:"+player01); System.out.println("周润发:"+player02); System.out.println("周星驰:"+player03); System.out.println("底牌:"+diPai); } }
|