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 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 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 K K K 3 10 8 6 5
Elina's cards are: 2 3 A J Q J 4 K 4 6 5 J 3 2 King 9
Card cards are: A 2 10
Output: Wind qing card is: 2 7 9 9 3 7 a Q 2 4 J 4 a 5 3 K 5
Brigitte's cards are: 8 2 Q 8 K 3 4 7 6 9 Q 10 3 5 Little Wang J
Elina's cards are: 4 2 J 7 K 8 6 J Ten A 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