JAVA随机发扑克牌_【求助】怎么实现从一副扑克牌中随机发不重复的两组5张牌...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我知道怎么发一组不重复的,两组就不会写了,我刚开始学,求指导!!

这是我写的发一组的

package huan_68;

import java.lang.reflect.Array;

import java.util.Arrays;

import java.util.Random;

public class Niuniu {

/**

* @param args

*/

public static void main(String[] args) {

String[] Zhuang=gen();

System.out.println(Arrays.toString(Zhuang));

}

public static String[] gen(){

String[] pool={"红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K","黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K","方片A","方片2","方片3","方片4","方片5","方片6","方片7","方片8","方片9","方片10","方片J","方片Q","方片K","红心A","红心2","红心3","红心4","红心5","红心6","红心7","红心8","红心9","红心10","红心J","红心Q","红心K"};

Random random=new Random();

boolean[] used=new boolean[pool.length];

String[] Zhuang=new String[5];

int i=0;

while(true){

int index=random.nextInt(pool.length);

if(used[index]){

continue;

}

Zhuang[i++]=pool[index];

used[index]=true;

if(i==Zhuang.length){

break;

}

}

return Zhuang;

}

}

有在的大神吗???

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值