1) 编写类Example01,创建两个String类型数组,其中一个用于存储牌的花色,一个用于存储牌的数字
2) 创建一个ArrayList集合作为牌盒,将大小王和不同花色不同数字的牌循环添加到集合中
3) 用Collections工具类的shuffle()方法洗牌
4) 创建三个ArrayList集合作为三个人的牌的集合,并循环发牌,要留三张底牌
5) 打印出三个人的牌和集合中留的三张底牌
package zuoye;
import java.util.*;
public class Example01 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] s1={"方块","红桃","黑桃","梅花"};
String[] s2={"A","1","2","3","4","5","6","7","8","9","10"
,"J","Q","K"};
ArrayList<String> list=new ArrayList<String>();
list.add("大王");
list.add("小王");
for(int i=0;i<s1.length;i++){
for(int j=0;j<s2.length;j++)
list.add(s1[i].concat(s2[j]));
}
Collections.shuffle(list);
ArrayList list1=new ArrayList();
ArrayList list2=new ArrayList();
ArrayList list3=new ArrayList();
for(int k=0;k<list.size()-3;k++){
if(k%3==0){
list1.add(list.get(k));
}
if(k%3==1){
list2.add(list.get(k));
}
if(k%3==2){
list3.add(list.get(k));
}
}
System.out.println("List1:"+list1);
System.out.println("List2:"+list2);
System.out.println("List3:"+list3);
System.out.println("底牌:");
for(int s=list.size()-3;s<list.size();s++){
System.out.print (list.get(s)+" ");
}
}
}