Package Com.loaderman.test;import Java.util.arraylist;import Java.util.collections;import java.util.HashMap;import Java.util.treeset;public class test{/** * * A: Case Demo * Code implementation for simulating bucket landlord shuffle and licensing and sorting cards * Analysis: * 1, buy a pair of poker, in fact, is to create a set of objects, the cards stored in * 2, Shuffle * 3, Licensing * 4, see the card */public static void Main (string[] args) {//1, buy a pair of poker, in fact, is to create a collection object, the cards are stored in string[] num = {"3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K", "A", "2"}; string[] color = {"Red peach", "spades", "Square piece", "Plum"}; Hashmap<integer, string> HM = new hashmap<> ();//Storage index and poker arraylist<integer> list = new arraylist< >////Store index int index = 0;//splicing poker and index and poker stored in HM for (string s1:num) {//Get number for (string s2:color) {//Get color hm.put (index, S2. Concat (S1)); List.add (index);//Add index 0 to 51 to the list collection index++;}} Add Xiao Wang to the Double column collection Hm.put (Index, "Xiao Wang"); List.add (index);//Add 52 index to the collection Index++;hm.put (Index, "King"); List.add (index);// Add the 52 index to the collection//2, Shuffle collections.shuffle (list),//3, licensing treeset<integer> Gaojin = new treeset<> (); treeset<integer> Longwu = new Treeset<> (); treeset<integer> me = 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));//store three cards in the hole collection}else if (i% 3 = = 0) {Gaojin.add (List.get (i));} else if (i% 3 = = 1) {Longwu.add (List.get (i));} else {Me.add (List.get (i));}} See Card Lookpoker (HM, Gaojin, "Gao Jin"), Lookpoker (HM, LONGWU, "Dragon Five"), Lookpoker (Hm, ME, "Feng Jia"), Lookpoker (HM, Dipai, "hole Cards");} /* * See card * 1, return value type void * 2, parameter list hashmap,treeset,string name */public static void Lookpoker (Hashmap<integer, string> HM ,treeset<integer> ts, String name) {System.out.print (name + "is:"); for (Integer I:ts) {//i represents each key in a double-column collection System.out . Print (Hm.get (i) + ""); System.out.println ();}}
Code implementation: Simulation of bucket landlord shuffle and licensing and sorting the cards to implement the code