[Java] 纯文本查看 复制代码 import java.util.ArrayList;
import java.util.Random;
public class Demo04 {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
Random r = new Random();
//生成6个红球的随机数
while(list.size()<6){
int a = r.nextInt(33)+1;
if(!list.contains(a)){
list.add(a);
}
}
//再生成一个篮球
while(true){
int b = r.nextInt(16)+1;
if(!list.contains(b)){
list.add(b);
break ;
}
}
System.out.println(list);
}
} |