有需要的可以看看!哈
import java.util.ArrayList;
import java.util.Collections;
public class LianXi斗地主 {
public static void main(String[] args) {
//买牌
String[] arr = {"黑桃","红桃","方片","梅花"};
String[] arr2 = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
ArrayList box = new ArrayList();
//添加每张牌
for (int i = 0; i < arr.length; i++) {
//获取每一个花色
for (int j = 0; j < arr2.length; j++) {
//获取每一个数
box.add(arr[i] + arr2[j]);
}
}
box.add("大王");
box.add("小王");
//System.out.println(box.size());
//洗牌
Collections.shuffle(box);
//System.out.println(box);
//发牌
ArrayList 林志玲 = new ArrayList();
ArrayList 林心如 = new ArrayList();
ArrayList 舒淇 = new ArrayList();
//留三张底牌给地主
for (int i = 0; i < box.size() - 3; i++) {
/*
* i = 0;i % 3 = 0;
* i = 1;i % 3 = 1;
* i = 2;i % 3 = 2;
* i = 3;i % 3 = 0;
* i = 4;i % 4 = 1;
* i = 5;i % 5 = 2;
*/
if(i % 3 == 0) {
林志玲.add(box.get(i));
}
else if(i % 3 == 1) {
林心如.add(box.get(i));
}
else if(i % 3 == 2) {
舒淇.add(box.get(i));
}
}
System.out.println("林志玲:" + 林志玲);
System.out.println("林心如:" + 林心如);
System.out.println("舒淇:" + 舒淇);
System.out.println("底牌:");
/* System.out.println(box.get(box.size() - 1));
System.out.println(box.get(box.size() - 2));
System.out.println(box.get(box.size() - 3));*/
for (int i = box.size() - 3; i < box.size(); i++) {
System.out.println(box.get(i));
}
}
}
2017-6-27 23:13 上传
点击文件名下载附件
下载积分: 吾爱币 -1 CB
683 Bytes, 下载次数: 6, 下载积分: 吾爱币 -1 CB
源代码