编译时,说有下面这个错误:
无法将 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;
}
}