----------------------
ASP.Net+Unity开发、
.Net培训、期待与您交流! ----------------------
public static void main(String[] args) {
List<Integer> list=new ArrayList<Integer>();
int i=0;
while (i!=10) {
int s=new Random().nextInt(20)+1;//nextInt()函数中的值是 在 0(包括)和指定值(不包括)之间均匀分布的
if (!list.contains(s)) {
list.add(s);
i++;
}
}
System.out.println(list.toString());
}
}---------------------- ASP.Net+Unity开发、 .Net培训、期待与您交流! ----------------------详细请查看: http://edu.csdn.net
//生成10个1至20的随机数。不能重复
public class Test3 {
public static void main(String[] args) {
List<Integer> list=new ArrayList<Integer>();
int i=0;
while (i!=10) {
int s=new Random().nextInt(20)+1;//nextInt()函数中的值是 在 0(包括)和指定值(不包括)之间均匀分布的
int
值,所以结果要加上一。if (!list.contains(s)) {
list.add(s);
i++;
}
}
System.out.println(list.toString());
}
}---------------------- ASP.Net+Unity开发、 .Net培训、期待与您交流! ----------------------详细请查看: http://edu.csdn.net