j2me 洗牌

//转自:http://www.cnblogs.com/lovetong/archive/2010/12/15/1907376.html
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;
    }

}


阅读更多
个人分类: 数据结构和算法
想对作者说点什么? 我来说一句

j2me模拟器

2011年12月20日 12.03MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭