有谁知道如何循环这次计算7次?
public static double[] getNumSeedsPerType(String[] treeTypes, int[] numTreesPerType, final double FIR_DIE) {
double numSeeds = 0;
double[] numSeedsPerType = new double[numTreesPerType.length];
for (int i = 0; i < treeTypes.length; i++) {
if (treeTypes[i].equalsIgnoreCase("fir")) {
// This part of the calculation
numSeeds = numTreesPerType[i] - (numTreesPerType[i] * FIR_DIE);
numSeedsPerType[i] = numSeeds + numTreesPerType[i];
}
}
return numSeedsPerType;
}
答案 0 :(得分:0)
如果我对您的代码的理解是正确的,您可以执行以下操作:
在循环内部更改此代码:
numSeeds = numTreesPerType[i] - (numTreesPerType[i] * FIR_DIE);
到此(因此您可以保留每次计算的结果):
numSeeds += numTreesPerType[i] - (numTreesPerType[i] * FIR_DIE);