- package cn.itcast_04;
-
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.TreeSet;
-
- public class PokerDemo {
- public static void main(String[] args) {
-
- HashMap<Integer, String> hm = new HashMap<Integer, String>();
-
-
- ArrayList<Integer> array = new ArrayList<Integer>();
-
-
-
- String[] colors = { "♠", "♥", "♣", "♦" };
-
- String[] numbers = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q",
- "K", "A", "2", };
-
-
- int index = 0;
-
- for (String number : numbers) {
- for (String color : colors) {
- String poker = color.concat(number);
- hm.put(index, poker);
- array.add(index);
- index++;
- }
- }
- hm.put(index, "小王");
- array.add(index);
- index++;
- hm.put(index, "大王");
- array.add(index);
-
-
- Collections.shuffle(array);
-
-
- TreeSet<Integer> fengQingYang = new TreeSet<Integer>();
- TreeSet<Integer> linQingXia = new TreeSet<Integer>();
- TreeSet<Integer> liuYi = new TreeSet<Integer>();
- TreeSet<Integer> diPai = new TreeSet<Integer>();
-
- for (int x = 0; x < array.size(); x++) {
- if (x >= array.size() - 3) {
- diPai.add(array.get(x));
- } else if (x % 3 == 0) {
- fengQingYang.add(array.get(x));
- } else if (x % 3 == 1) {
- linQingXia.add(array.get(x));
- } else if (x % 3 == 2) {
- liuYi.add(array.get(x));
- }
- }
-
-
- lookPoker("风清扬", fengQingYang, hm);
- lookPoker("林青霞", linQingXia, hm);
- lookPoker("刘意", liuYi, hm);
- lookPoker("底牌", diPai, hm);
- }
-
-
- public static void lookPoker(String name, TreeSet<Integer> ts,
- HashMap<Integer, String> hm) {
- System.out.print(name + "的牌是:");
- for (Integer key : ts) {
- String value = hm.get(key);
- System.out.print(value + " ");
- }
- System.out.println();
- }
- }
posted @
2017-04-04 14:03
ScaleZ
阅读(
381)
评论()
编辑
收藏
举报
点击右上角即可分享
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步