Code implementation: Simulation of bucket landlord shuffle and licensing and sorting the cards to implement the code

Source: Internet
Author: User
Tags shuffle

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.