Random rd = new Random();
int i = rd.NextInt(100)+1
public class RandomTest
{
private static final int SET_SIZE = 6;
public static final int RANDOM_MAX_VALUE = 33;
private static Random random = new Random();
public static void main(String[] args)
{
Set set = new HashSet();
while (set.size() < SET_SIZE )
{
Integer integer =new Integer(random.nextInt(RANDOM_MAX_VALUE) );
set.add(integer);
}
Iterator it = set.iterator();
while(it.hasNext())
{
System.out.println("Output A ball:"+it.next());
}
int i;
i=random.nextInt(16)+1;
System.out.print("Output B ball:"+i);
}
}
int i = rd.NextInt(100)+1
public class RandomTest
{
private static final int SET_SIZE = 6;
public static final int RANDOM_MAX_VALUE = 33;
private static Random random = new Random();
public static void main(String[] args)
{
Set set = new HashSet();
while (set.size() < SET_SIZE )
{
Integer integer =new Integer(random.nextInt(RANDOM_MAX_VALUE) );
set.add(integer);
}
Iterator it = set.iterator();
while(it.hasNext())
{
System.out.println("Output A ball:"+it.next());
}
int i;
i=random.nextInt(16)+1;
System.out.print("Output B ball:"+i);
}
}
本文探讨了使用随机数生成器创建集合的过程,并通过实例展示了如何实现并输出指定大小的集合,以及额外生成一个随机数。
850

被折叠的 条评论
为什么被折叠?



