package Day07;
import java.util.*;
public class LianXi07 {
public static void main(String[] args) {
HashMap<Integer,String> hm =new HashMap<>();
ArrayList<Integer> a=new ArrayList<>();
// Set<Map.Entry<Integer, String>> en = hm.entrySet();
String [] arr1={"方片","梅花","红桃","黑桃"};
String [] arr2={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
int idex=0;
for (String s : arr2) {
for (String s1 : arr1) {
hm.put(idex,(s1+s));
a.add(idex);
idex++;
}
}
hm.put(idex,"小王");
a.add(idex);
idex++;
hm.put(idex,"大王");
a.add(idex);
/* System.out.println(hm);
System.out.println(a);*/
Collections.shuffle(a);
TreeSet<Integer> gy=new TreeSet<>();
TreeSet<Integer> lb=new TreeSet<>();
TreeSet<Integer> zf=new TreeSet<>();
TreeSet<Integer> dp=new TreeSet<>();
for (int i = 0; i <a.size() ; i++) {
Integer s = a.get(i);
if (i>=a.size()-3){
dp.add(s);
}else if (i%3==0){
gy.add(s);
}else if (i%3==1){
lb.add(s);
}else{
zf.add(s);
}
// System.out.println(gy);
//faPai("关羽",gy,hm);
/*faPai("刘备",lb,hm);
faPai("张飞",zf,hm);*/
}
faPai("关羽",gy,hm);
faPai("刘备",lb,hm);
faPai("张飞",zf,hm);
faPai("底牌",dp,hm);
}
public static void faPai(String name,TreeSet<Integer> ts,HashMap<Integer,String> hm){
System.out.print(name+"的牌是:");
for (Integer t : ts) {
String s = hm.get(t);
System.out.print(s+" ");
}
System.out.println();
}
}
|
|