程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> Java完成洗牌發牌的辦法

Java完成洗牌發牌的辦法

編輯:關於JAVA

Java完成洗牌發牌的辦法。本站提示廣大學習愛好者:(Java完成洗牌發牌的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Java完成洗牌發牌的辦法正文


本文實例講述了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法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved