判断是否重复报错
模仿双色球前6位package balls;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class balls {
public static void main(String[] args) {
List list=new ArrayList();
for (int i = 1 ; i <= 33; i++) {
list.add(i);
//System.out.println(list);
}
List balls=new ArrayList();
Random random=new Random();
for (int i = 0; i < 6; i++) {
int r=random.nextInt(list.size());
balls.add(list.get(r));
for(int j=0;j<6;j++){
if(list.get(r)==balls.get(j)){//现在得到的球和原来的数字对比不重复,此行代码报错
balls.remove(i);i--;
}
}
System.out.println(balls);
}
}
}