Java to implement the method of shuffling and dealing CARDS
- 2020-04-01 04:02:59
- OfStack
The example of this article describes the Java implementation of shuffling and dealing methods. Share with you for your reference. The details are as follows:
import java.util.*;
public class Main {
static int numbersOfPlayers = 4;
static int numbersOfHandCard = 13;
public static void main(String[] args) {
// TODO code application logic here
String[] player = {" wang "," Xiao zhang, "," Xiao zhao "," The small white "};
String sentence = " The hand CARDS are: ";
String[] huase = {"♥","♣","♦","♠"};
String[] paiValue ={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
List deak = new ArrayList();
for(int i = 0;i < 4;i++){
for(int j = 0; j < 13;j++)
{
deak.add(huase[i]+paiValue[j]);
}
}
Collections.shuffle(deak);
for(int i = 0;i < numbersOfPlayers;i++){
System.out.print(player[i]+sentence);
System.out.println(dealHand(deak, numbersOfHandCard));
}
}
public static List dealHand(List Ls,int n){
int sizePai = Ls.size();
List handView = Ls.subList(sizePai - n, sizePai);
List hand = new ArrayList(handView);
handView.clear();
return hand;
}
}
I hope this article has been helpful to your Java programming.