Code:
Package com.oracle.demo02; Import of java.util.ArrayList; Import java.util.Collections; Import the java.util.HashMap; public class DouDiZhu { // landlord (Licensing) public static void main (String [] args) { // definition of poker the Map the HashMap <Integer, String> = pooker new new the HashMap <Integer, String> (); // define the number of playing cards with the set of the ArrayList <Integer> = pookerNumber new new the ArrayList <Integer> (); // package data String [] color = { "♠ ", "♦", "♥", "♣" ", "♦", "♥", "♣"}; // test // System.out.println (pooker); // shuffling: upset elements in a set sequence (random) -> Collections.shuffle (); Collections.shuffle (pookerNumber); // the System.out. the println (pookerNumber); // create four containers the ArrayList <Integer> = Player1 new new the ArrayList <Integer> (); the ArrayList <Integer> = player2 new new the ArrayList <Integer> (); the ArrayList <Integer> = player3 new new the ArrayList <Integer> (); the ArrayList <Integer> = bottom new new the ArrayList <Integer> (); //发牌 for (int i = 0; i < pookerNumber.size(); i++) { //将前三张牌作为底牌 if (i<3) { bottom.add(pookerNumber.get(i)); }else if(i%3==0){ player1.add(pookerNumber.get(i)); }else if(i%3==1){ player2.add(pookerNumber.get(i)); }else if(i%3==2){ player3.add(pookerNumber.get(i)); } } //To sort card four containers (straighten) -> the Collections.sort (); the Collections.sort (Player1); the Collections.sort (player2); the Collections.sort (player3); the Collections.sort (bottom); / / See card look ( "slag slag hui" , pooker, Player1); look ( "Liang atrophy" , pooker, player2); look ( "Zhao immortal" , pooker, player3); look ( "cards" , pooker, bottom) ; } public static void look (String name, the HashMap <Integer, String> pooker, the ArrayList <Integer> Player) { of System.out.print (name + ":" ); for (int number : player) { System.out.print(pooker.get(number)+" "); } System.out.println(); } }
Idea: