public static void main(String[] args) {
//创建红色集合
ArrayList<Integer> red = new ArrayList<>();
int temp = 0;
for (int i = 1; i <= 6; i++) {
int num = (int) (Math.random() * 33 + 1);
//collections类中的方法
//int frequency(Collection,Object);返回指定集合中的指定元素出现的次数从0开始计数
if (Collections.frequency(red, num) == 3) {
//System.out.println("Collections.frequency(red, num)" + Collections.frequency(red, num));
i--;
continue;
} else {
red.add(num);
}
}
//System.out.println(red);
//创建篮球集合
ArrayList<Integer> bs = new ArrayList<>();
int num = (int) (Math.random() * 16 + 1);
bs.add(num);
//升序排序
Collections.sort(red);
//定义集合接收
ArrayList<Integer> ball = new ArrayList<>();
//倒叙输出
for (int i = red.size() - 1; i >= 0; i--) {
ball.add(red.get(i));
}
ball.add(bs.get(0));//添加篮球
System.out.println(ball);
}