首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

至于Random中的nextInt()?

2011-12-20 
关于Random中的nextInt()?????编译时,说有下面这个错误:无法将java.util.Random中的nextInt()应用于(int)g

关于Random中的nextInt()?????
编译时,说有下面这个错误:
无法将   java.util.Random   中的   nextInt()   应用于   (int)
getnum   =   random.nextInt(27);
 请问这个怎么改呀?这是怎么回事?谢谢!!!

[解决办法]
import java.util.*;

public class Test {
public static void main(String[] args){
ArrayList arr = new Test().getRandom(50);
//排序
Collections.sort(arr);
//遍??出
Iterator it = arr.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
public ArrayList getRandom(int num){
ArrayList randomNum = new ArrayList();
Random random = new Random();
int temp = 0;
for (int i = 0;i < num; i ++){
temp = random.nextInt(num);
int nums = temp + 1;
//判断是否重?
if (randomNum.indexOf(new Integer(nums)) == -1){
randomNum.add(new Integer(nums));
}else{
i -- ;
}
}
return randomNum;
}
}

热点排行