Java实现洗牌发牌的方法
程序员文章站
2024-03-04 22:18:42
本文实例讲述了java实现洗牌发牌的方法。分享给大家供大家参考。具体如下:
import java.util.*;
public class main {...
本文实例讲述了java实现洗牌发牌的方法。分享给大家供大家参考。具体如下:
import java.util.*; public class main { /** * @param args the command line arguments */ static int numbersofplayers = 4; static int numbersofhandcard = 13; public static void main(string[] args) { // todo code application logic here string[] player = {"小王","小张","小赵","小白"}; string sentence = "的手牌是:"; 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; } }
希望本文所述对大家的java程序设计有所帮助。