import java.util.ArrayList; import java.util.Collections; public class Demo { public static void main(String[] args) { //扑克牌的花色 ArrayList<String> colors = new ArrayList<>(); colors.add("♦"); colors.add("♣"); colors.add("♠"); colors.add("♥"); //扑克牌的数字 ArrayList<String> numbers = new ArrayList<>(); numbers.add("A"); for (int i = 2; i <= 10; i++) { //整型转换成字符串型 numbers.add(String.valueOf(i)); } numbers.add("J"); numbers.add("Q"); numbers.add("K"); //添加‘花色+数字’组合的扑克牌 ArrayList<String> cards = new ArrayList<>(); for (String i1 : colors) { for (String i2 : numbers) { //字符串拼接 cards.add(i1.concat(i2)); } } //添加大小王,所有扑克牌就添加完毕 cards.add("小王"); cards.add("大王"); //检查扑克牌全部卡 //System.out.println(cards); //打乱扑克牌顺序 Collections.shuffle(cards); //玩家的列表 ArrayList<String> player1 = new ArrayList<>(); ArrayList<String> player2 = new ArrayList<>(); ArrayList<String> player3 = new ArrayList<>(); //给每位玩家17张牌 for (int i = 0; i < cards.size() - 3; i += 3) { player1.add(cards.get(i)); player2.add(cards.get(i + 1)); player3.add(cards.get(i + 2)); } //剩下的是底牌 ArrayList<String> dipai = new ArrayList<>(); for (int i = cards.size() - 3; i < cards.size(); i++) { dipai.add(cards.get(i)); } //重新按顺序排序 Collections.sort(player1); Collections.sort(player2); Collections.sort(player3); //每个人的牌和底牌 System.out.println(player1); System.out.println(player2); System.out.println(player3); System.out.println("底牌是:" + dipai); } }