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> (); BR style= "Word-wrap:break-word" > arraylist<string> Liuyi = new arraylist<string> ();
arraylist<string> Dipai = new arraylist<string> (); for (int x = 0; x < array.size (); + +) {
& Nbsp;if (x >= array.size ()-3) {
Dipai.add (Array.get (x));
} else if (x 3 = = 0) {
fengqingyang.ad D (Array.get (x));
} else if (x% 3 = = 1) {
LinQ Ingxia.add (Array.get (x));
} else if (x% 3 = = 2) {
LiuY I.add (Array.get (x));
}
&NBSP;&NBSP;} Look at the 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 is 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 of the cards are:? A? 2? 10
Output: Wind Qing's 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
The cards are: 6 king? A save it here, and slowly realize
Flexible application of data structures of Java collection classes