【发布时间】:2014-05-30 16:22:16
【问题描述】:
我有一个方法会根据值返回一个双精度值。数组中的每个 int 将介于 1 到 6 之间,表示连续掷骰子。
数组可以是 16 个插槽,也可以小到 4 个,并且顺序很重要。我不知道如何在 java 中编写代码来查看总计至少为 16 的每个排列。在线查找没有任何帮助。
下面是我可怜的代码
public double findMax() {
int[] dice = new int[gameBoard.length];
for(int x : dice) x = 1;
double max = playGame(dice);
/*
int pos = 0;
for(int i = 0; i < dice.length; i++) {
double test = playGame(dice);
if(test > max) test = max;
*/
//This is where I need help, to use the int[] dice for all combinations
//playGame(dice) yields a double
}
【问题讨论】:
-
所以本质上你想要那个数组的所有组合,总共可以得到 16 个?
-
顺序敏感是的,数组大小不固定,让我更困惑
-
但是正如你所提到的,它是关于一个骰子的......如何排列超过 6 个元素?
-
也许我可以更清楚。每个索引都是掷骰子,结果是存储在骰子中的 int。因此,为了达到 16,我将掷出最多 16 个骰子,每个索引的 int 为 1
-
知道了..稍后会为您提供代码..
标签: java arrays algorithm loops max