好友
阅读权限10
听众
最后登录1970-1-1
|
有需要的可以看看!哈
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<String> box = new ArrayList<String>();
//添加每张牌
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<String> 林志玲 = new ArrayList<String>();
ArrayList<String> 林心如 = new ArrayList<String>();
ArrayList<String> 舒淇 = new ArrayList<String>();
//留三张底牌给地主
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));
}
}
} |
-
-
work04.zip
683 Bytes, 下载次数: 7, 下载积分: 吾爱币 -1 CB
源代码
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|