#1、我们可以通过随机数0~1来判断是否中将
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
// 中奖概率,假设中奖概率为20%
double winningProbability = 0.2;
// 生成随机数
Random random = new Random();
// 生成0到1之间的随机数,如果随机数小于中奖概率,则认为中奖
double randomNumber = random.nextDouble();
if (randomNumber < winningProbability) {
System.out.println("Congratulations! You win the lottery!");
} else {
System.out.println("Sorry, you didn't win this time.");
}
}
}