1、蓝色球5个,1~35 不能重复
2、红色球2个,1~12 不能重复
代码如下:
public class demo {public static void main(String[] args) {System.out.println("现在时间为"+ LocalDateTime.now()+",今天体彩大乐透的开奖结果为:");List<Integer> list = new ArrayList<Integer>();Random random = new Random();while (true){int i = random.nextInt(34);int ii = i+1;if (!list.contains(ii)){list.add(ii);}if (list.size() == 5){break;}}System.out.println("今天蓝色球的开奖结果为:"+list);List<Integer> list1 = new ArrayList<Integer>();while (true){int i = random.nextInt(11);int ii = i+1;if (!list1.contains(ii)){list1.add(ii);}if (list1.size() == 2){break;}}System.out.println("今天红色球的开奖结果为:"+list1);}
}
三次输出结果为: