Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用数组进行多个输出?_Java_Arrays_If Statement_Netbeans_Dice - Fatal编程技术网

Java 如何使用数组进行多个输出?

Java 如何使用数组进行多个输出?,java,arrays,if-statement,netbeans,dice,Java,Arrays,If Statement,Netbeans,Dice,当我写入System.out.print(骰子)时,输出是随机生成的数字,如下所示: [3|4|7|6|6] 如何使用数组具有多个值 /** * This program rolls Yahtzee! dice 1,000,000 times, recording the number of * Yahtzees which occur. After the trials statistics are produced. */ /** * @param args the comma

当我写入
System.out.print(骰子)
时,输出是随机生成的数字,如下所示:

[3|4|7|6|6]
如何使用数组具有多个值

/**
 * This program rolls Yahtzee! dice 1,000,000 times, recording the number of 
 * Yahtzees which occur. After the trials statistics are produced.
 */

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code your application logic here
    Scanner input = new Scanner(System.in);
    Random generator = new Random();
    YahtzeeDice dice = new YahtzeeDice(generator);
    System.out.print(dice);
    }
}

没有足够的声誉来评论。我不完全确定你需要什么。 您当前的代码是否从一次运行中生成这5个数字?你的雅思迪奇课程是什么? 如果您想将骰子的值记录到数组中,您可以简单地将其放入循环中,并继续向数组中添加骰子:

public List<YahtzeeDice> generate(int n) {
    List<YahtzeeDice> results = new ArrayList<YahtzeeDice>();
    YahtzeeDice dice;
    for(int i = 0; i < n; i++) {
        dice = new YahtzeeDice(new Random());
        results.add(dice);
    }
    return results;
}
公共列表生成(int n){
列表结果=新建ArrayList();
雅特泽德骰子;
对于(int i=0;i
像这样的?还没有测试是否编译。 然后,您需要从主菜单调用此选项:

List<YahtzeeDice> diceResults = generate(1000000);
List diceResults=generate(1000000);

在这里或多或少地检查相同的问题。