首页 > 解决方案 > 同时初始化两个不同的随机变量

问题描述

我正在使用'java.util.Random'编写一个脚本,并且我试图为同一个println初始化两个随机变量,但它只有在我注释掉其中一个变量时才有效。这是我的问题所在的代码:

Random a = new Random();
        date = a.nextInt(29) + 1;
        year = a.nextInt(2019 - 2044)+ 1;

        System.out.println("The best day of your life will be on " + month +       " " + date + ","+ " " + year + ".....give or take.\n");
        System.out.println("Which date of the month do you believe is your   luckiest?");

我不知道如何同时初始化“日期”和“年份”。任何帮助表示赞赏。

标签: variablesrandom

解决方案


推荐阅读