Package cn.itcast_03; import java.util.ArrayList;
Import java.util.Collections; /*
* Simulated bucket landlord shuffle and licensing
*
Analysis
* A: Create a card box
* B: Pack cards
* C: Shuffle
* D: Licensing
* E: Look at the cards
*/
public class Pokerdemo {
public static void Main (string[] args) {
Create a card box
arraylist<string> array = new arraylist<string> (); Pack cards
Spades A, Spades 2, Spades 3,... Black Peach K
Red Peach a,...
Plum Blossom a,...
Block a,...
Define a suit array
string[] colors = {"♠", "♥", "♣", "♦"};
Define an array of points
string[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"J", "Q", "K"};
Pack cards
for (String color:colors) {
for (String number:numbers) {
Array.add (Color.concat (number));
}
}
Array.add ("Xiao Wang");
Array.add ("King"); //Shuffle
Collections.shuffle (array); //System.out.println ("array:" + array); //Licensing
arraylist<string> Fengqingyang = new arraylist<string> ();
arraylist<string> Linqingxia = new arraylist<string> ();
arraylist<string> Liuyi = new arraylist<string> ();
arraylist<string> Dipai = new arraylist<string> (); for (int x = 0; x < array.size (); + +) {
if (x >= array.size ()-3) {
Dipai.add (Array.get (x));
} else if (x% 3 = = 0) {
Fengqingyang.add (Array.get (x));
} else if (x% 3 = = 1) {
Linqingxia.add (Array.get (x));
} else if (x% 3 = = 2) {
Liuyi.add (Array.get (x));
}
} //Look at cards
Lookpoker ("Wind Qing", Fengqingyang);
Lookpoker ("Brigitte", Linqingxia);
Lookpoker ("Elina", Liuyi); lookpoker ("hole cards", Dipai);
}public static void Lookpoker (String name, arraylist<string> array) {
System.out.print (name + "The card is:");
for (String S:array) {
System.out.print (S + "");
}
System.out.println ();
}
} Test multiple times
Output: The wind of the card is: Xiao Wang ♦8♥10♦5♣q♥4♣7♣8♠9♦a♠4♥7♠2♦6♠7♥8♣9
Brigitte's cards are: ♦q♥5♥9♠a♠6♣3♠q♦7♦10♠k♦k♣k♥3♠10♠8♥6♠5
Elina's cards are: ♥2♠3♥a♠j♥q♣j♦j♣4♥k♦4♣6♣5♥j♦3♦2 King ♦9
The cards are: ♣a♣2♣10
Output: Wind of the card is: ♦2♠7♥9♦9♥3♥7♠a♠q♣2♣4♠j♦4♦a♣5♠3♥k♦5
Brigitte's cards are: ♥10♦8♥2♣q♣8♠k♦3♠4♣7♠6♠9♦q♠10♣3♥5 Xiao Wang ♣j
Elina's cards are: ♥4♠2♦j♦7♦k♥8♣6♥j♣10♥a♦10♠8♠5♥q♣9♥6♣k
Card cards are: ♦6 King ♣a save it here, and slowly realize
Flexible application of data structures of Java collection classes