该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我知道怎么发一组不重复的,两组就不会写了,我刚开始学,求指导!!
这是我写的发一组的
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;
}
}
有在的大神吗???