标签:class map layer span sys div imp import 排列
import java.util.*; public class NewDouDiZhu { public static void main(String[] args) { HashMap<Integer,String> poker= new HashMap<>(); //1.组装牌 ArrayList<Integer> suoyin = new ArrayList<>(); List<String> color = new ArrayList<>(); color.add("红桃"); color.add("方块"); color.add("黑桃"); color.add("梅花"); String[] number = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"}; int index = 0; for (String n:number){ for (String c:color){ poker.put(index,c+n); suoyin.add(index); index++; } } poker.put(index++,"大王"); poker.put(index++,"小王"); System.out.println(poker); System.out.println(suoyin); //2.洗牌 Collections.shuffle(suoyin); System.out.println(suoyin); //3.发牌 ArrayList<Integer> player1 = new ArrayList<>(); ArrayList<Integer> player2 = new ArrayList<>(); ArrayList<Integer> player3 = new ArrayList<>(); ArrayList<Integer> dipai = new ArrayList<>(); for (int n =0;n<suoyin.size();n++) { Integer in = suoyin.get(n); if (n>=50){ dipai.add(in); }else if (n%3==0){ player1.add(in); }else if (n%3==1){ player2.add(in); }else if(n%3==2){ player3.add(in); } } Collections.sort(player1); Collections.sort(player2); Collections.sort(player3); System.out.println("底牌是: "+dipai); System.out.println(player1); System.out.println(player3); System.out.println(player2); //看牌 for (Integer s:player1){ String pai =poker.get(s); System.out.print(pai+" "); } } }
标签:class map layer span sys div imp import 排列
原文地址:https://www.cnblogs.com/yeqingyun/p/13223946.html