package com.tengfei.lesson06;   
import java.util.Vector;  
import java.util.LinkedList;  
import java.util.Random;  
import java.util.ListIterator;  
  
public class DealCards {  
  public static void main(String[] args) {  
    String[] suits = {"C", "D", "H", "S"};  
    String[] cardValues = { "1","2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};  
  
    int cardsInDeck = 52;  
    Vector<String> deck = new Vector<String>(cardsInDeck);  
    LinkedList<String> shuffledDeck = new LinkedList<String>();  
    Random chooser = new Random();             // Card chooser  
  
    // Load the deck  
    for(String suit : suits) {  
      for(String cardValue : cardValues) {  
        deck.add(cardValue+suit);  
      }  
  }  
  
    // Select cards at random from the deck to transfer to shuffled deck  
    int selection = 0;                        // Selected card index  
    for(int i = 0 ; i<cardsInDeck ; i++) {  
      selection = chooser.nextInt(deck.size());  
      shuffledDeck.add(deck.remove(selection));  
    }  
      
    // Deal the cards from the shuffled deck into four hands  
    StringBuffer[] hands = { new StringBuffer("Hand 1:"), new StringBuffer("Hand 2:"),  
                             new StringBuffer("Hand 3:"), new StringBuffer("Hand 4:")};  
    ListIterator cards = shuffledDeck.listIterator();  
     
    while(cards.hasNext()) {   
      for(StringBuffer hand : hands) {  
        hand.append(' ').append((String)(cards.next()));  
      }  
    }  
  
    // Display the hands  
    for(StringBuffer hand : hands) {  
      System.out.println(hand.toString());  
    }  
  }  
}  
最近下载更多
851690469  LV1 2023年10月18日
anthonyz  LV2 2022年2月9日
balabalazy  LV1 2021年4月8日
厚烧海苔  LV1 2021年3月31日
2196316269  LV10 2021年2月25日
qq454952101  LV4 2021年2月5日
菜鸟选手22  LV3 2020年11月24日
1992957164  LV1 2020年11月24日
Mac Wang  LV1 2020年5月12日
kevin555  LV2 2020年5月1日
最近浏览更多
851690469  LV1 2023年10月18日
zdmxjxj  LV9 2023年2月13日
WanLiuYun  LV12 2022年12月9日
yada233  LV7 2022年6月16日
BestClever  LV32 2022年4月27日
anthonyz  LV2 2022年2月9日
好的好的  LV8 2021年6月18日
balabalazy  LV1 2021年4月8日
厚烧海苔  LV1 2021年3月31日
2196316269  LV10 2021年2月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友