思路分析:
代码:
package demo01;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class douDiZhu {
public static void main(String[] args) {
ArrayList<String> pai = new ArrayList<>();//存储牌
String [] color = {"♠","♥","♣","♦"};//存储花色
String [] number= {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};//存储号码
pai.add("大王");
pai.add("小王");
for (String s:color){//装牌
for (String e:number){
pai.add(s+e);
}
}
System.out.println("未洗牌前:"+pai);
//洗牌,利用工具类Collections
Collections.shuffle(pai);//洗牌
System.out.println("洗牌后:"+pai);
ArrayList<String> palyer1 = new ArrayList<>();
ArrayList<String> palyer2 = new ArrayList<>();
ArrayList<String> palyer3 = new ArrayList<>();
ArrayList<String> diPai = new ArrayList<>();
for (int i = 0 ; i <pai.size(); i++){//发牌
String poker = pai.get(i);
if(i>=51){
diPai.add(poker);
}
else if(i%3==0){
palyer1.add(poker);
}
else if(i%3==1){
palyer2.add(poker);
}
else if(i%3==2){
palyer3.add(poker);
}
}
System.out.println("周润发:"+palyer1);
System.out.println("高进:"+palyer2);
System.out.println("刘德华:"+palyer3);
System.out.println("底牌:"+diPai);
}
}