package com.heima.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class Test3 {
public static void main(String[] args) {
String[] num = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
String[] color = {"红桃","黑桃","方片","梅花"};
HashMap<Integer, String> hm = new HashMap<>();
ArrayList<Integer> list = new ArrayList<>();
int index = 0;
for(String s1 : num) { for(String s2 : color) {
hm.put(index, s2.concat(s1));
list.add(index);
index++;
}
}
hm.put(index, "小王");
list.add(index);
index++;
hm.put(index, "大王");
list.add(index);
Collections.shuffle(list);
TreeSet<Integer> gaojin = new TreeSet<>();
TreeSet<Integer> longwu = new TreeSet<>();
TreeSet<Integer> me = new TreeSet<>();
TreeSet<Integer> dipai = new TreeSet<>();
for(int i = 0; i < list.size(); i++) {
if(i >= list.size() - 3) {
dipai.add(list.get(i));
}else if(i % 3 == 0) {
gaojin.add(list.get(i));
}else if(i % 3 == 1) {
longwu.add(list.get(i));
}else {
me.add(list.get(i));
}
}
lookPoker(hm, gaojin, "高进");
lookPoker(hm, longwu, "龙五");
lookPoker(hm, me, "赵云");
lookPoker(hm, dipai, "底牌");
}
public static void lookPoker(HashMap<Integer, String> hm,TreeSet<Integer> ts ,String name) {
System.out.print(name + "的牌是:");
for(Integer i : ts) { //i代表双列集合中的每一个键
System.out.print(hm.get(i) + " ");
}
System.out.println();
}
}
大神们,你们看看这个程序!
public static void lookPoker(HashMap<Integer, String> hm,TreeSet<Integer> ts ,String name) {
System.out.print(name + "的牌是:");
for(Integer i : ts) { //i代表双列集合中的每一个键
System.out.print(hm.get(i) + " ");
}
这个部分不是明白,麻烦给解释一下,谢谢啦
|