java 洗牌 发牌
import java.util.LinkedList;
import java.util.Random;
public class Work3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] shuzi={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
String[] yanshe={"黑桃","红桃","方块","梅花"};
LinkedList lin=new LinkedList();
LinkedList lin1=new LinkedList();
LinkedList lin2=new LinkedList();
LinkedList lin3=new LinkedList();
LinkedList lin4=new LinkedList();
for (int i = 0; i < 52; i++) {
String str=yanshe[i/13]+shuzi[i%13];
lin.add(str);
}
System.out.println(lin);
Random rd=new Random();
for(int i=0;i<52;i++)
{
int j = rd.nextInt(52);//生成随机数
String temp = (String)lin.get(i);//交换
lin.set(i, lin.get(j));
lin.set(j, temp);
}
for (int i = 0; i < lin.size(); i++) {
if (i%4==0) {
lin1.add(lin.get(i));
}else if(i%4==1) {
lin2.add(lin.get(i));
}else if(i%4==2) {
lin3.add(lin.get(i));
}else if(i%4==3) {
lin4.add(lin.get(i));
}
}
System.out.println(lin);
System.out.println(lin1);
System.out.println(lin2);
System.out.println(lin3);
System.out.println(lin4);
System.out.println(lin.size());
}
}