import java.awt.Color;
import java.awt.image.LookupOp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
public class Demo {
public static void main(String[] args) {
String s[] = { "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 s2 : s) {
for (String s3 : color) {
HM.put(index, s3.concat(s2));
index++;
list.add(index);
}
}
HM.put(index, "大王");
list.add(index);
index++;
HM.put(index, "小王");
list.add(index);
Collections.shuffle(list); //将索引打乱顺序
TreeSet<Integer> A = new TreeSet<>();
TreeSet<Integer> B = new TreeSet<>();
TreeSet<Integer> C = 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 == 1) {
A.add(list.get(i));
} else if (i % 3 == 0) {
B.add(list.get(i));
} else {
C.add(list.get(i));
}
}
LookPoker(HM,A,"a");
LookPoker(HM,B,"b");
LookPoker(HM,C,"C");
LookPoker(HM,dipai,"DIPAI");
//System.out.println(HM.size());
}
public static void LookPoker(HashMap<Integer, String> hp,TreeSet<Integer> ts,String name) {
System.out.print(name+"的牌是:");
for(Integer it:ts) {
System.out.print(hp.get(it)+" "); //
}
System.out.println();
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class Demo {
public static void main(String[] args) {
String num[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
String color[] = { "红心", "黑桃", "方块", "梅花", };
ArrayList<String> poker = new ArrayList<>();
for (String S1 : color) {
for (String s2 : num) {
poker.add(S1.concat(s2));
}
}
poker.add("大王");
poker.add("小王");
Collections.shuffle(poker);
ArrayList<String> a = new ArrayList<>();
ArrayList<String> b = new ArrayList<>();
ArrayList<String> c = new ArrayList<>();
ArrayList<String> dipai = new ArrayList<>();
for (int i = 0; i < poker.size(); i++) {
if (i >= poker.size() - 3) {
dipai.add(poker.get(i));
} else if (i % 3 == 0) {
a.add(poker.get(i));
} else if (i % 3 == 1) {
b.add(poker.get(i));
} else {
c.add(poker.get(i));
}
}
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(dipai);
System.out.println(poker.size());
}
}