黑马程序员技术交流社区
标题:
代码报错,求解 long round = Math.round(Math.random())咋用??
[打印本页]
作者:
liujian5461267
时间:
2016-4-30 18:09
标题:
代码报错,求解 long round = Math.round(Math.random())咋用??
import java.util.Comparator;
import java.util.Random;
import java.util.TreeSet;
//产生十个1-20的随机数,从大到小排序,不能重复
public class RandomDamo {
public static void main(String[] args) {
Random random = new Random();
TreeSet<Integer> ts= new TreeSet<Integer>(new Comparator<Integer>() {
@Override
public int compare(Integer a1, Integer a2) {
return a2-a1;
}
});
int count=0;
while(count<10) {
long round = Math.round(Math.random());
int i= (int)(round*20)+1;
//int i= random.nextInt(20);
if (!ts.contains(i)) {
ts.add( i);
count++;
}
}
for (Integer integer : ts) {
System.out.print(integer+", ");
}
}
}
复制代码
作者:
liujian5461267
时间:
2016-4-30 19:31
整个论坛都没有人,哎
作者:
东方乔恩
时间:
2016-4-30 20:57
大神的代码,看不懂,还没有学到啊
作者:
huaihkiss
时间:
2016-4-30 21:05
Round是什么
作者:
liujian5461267
时间:
2016-5-1 08:07
math.random()能不能实现随机数啊??
作者:
WDzyll
时间:
2016-5-1 08:58
liujian5461267 发表于 2016-5-1 08:07
math.random()能不能实现随机数啊??
我记得好像可以的
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2