**
排序思想
**
在这里插入代码片package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test03 {
public static void main(String[] args) {
Map<Integer, String> pokerMap = new HashMap<Integer, String>();
List<Integer> pookerList = new ArrayList<Integer>();
int count=0;
String[] colors = {"♠","♣","♥","♦"};
//数组存储点数
String[] numbers = {"3","4","5","6","7","8","9","10","j","q","k","A","2"};
for (int i = 0; i < numbers.length; i++) {
for (int j = 0; j < colors.length; j++) {
pokerMap.put(count, colors[j]+numbers[i]);//得到了一副扑克牌
pookerList.add(count);
count++;
}
}
pokerMap.put(52, "😀");
pokerMap.put(53, "👴");
pookerList.add(52);
pookerList.add(53);
List<Integer> player1 = new ArrayList<Integer>();
List<Integer> player2 = new ArrayList<Integer>();
List<Integer> player3 = new ArrayList<Integer>();
List<Integer> bottom = new ArrayList<Integer>();
Collections.shuffle(pookerList);
//System.out.println(pookerList);
for (int i = 0; i < pookerList.size(); i++) {
if (i < 3 ) {
bottom.add(pookerList.get(i));
}else if (i%3 == 0) {
player1.add(pookerList.get(i));
}else if (i%3 == 1) {
player2.add(pookerList.get(i));
}else if (i%3 == 2 ) {
player3.add(pookerList.get(i));
}
}
Collections.sort(player1);
Collections.sort(player2);
Collections.sort(player3);
Collections.sort(bottom);
look("张三", pokerMap, player1);
look("李四", pokerMap, player2);
look("王五", pokerMap, player3);
look("底牌", pokerMap, bottom);
}
public static void look(String name,Map<Integer, String> pokerMap,List<Integer> player ) {
System.out.println(name+":");
for(Integer p:player) {
String value = pokerMap.get(p);
System.out.print(value +" ");
}
System.out.println("");
}
}
效果图