我的计算产生了多个结果。结果是double
类型。所以我将结果存储在double []
中。
private void calculateProducedEnergy() {
for (Integer s: mWeatherProfile.getSunshine()) {
for (Double w: mWeatherProfile.getWeatherConditions()) {
mProducedEnergy = s * w * mPvSystem.getEfficiency() * mPvSystem.getPanelSurface();
}
}
}
答案 0 :(得分:2)
您可以通过两种方式解决此问题。如果您希望将变量mProducedEnergy
保留为数组,那么
private void calculateProducedEnergy() {
int counter = 0;
for (Integer s: mWeatherProfile.getSunshine()) {
for (Double w: mWeatherProfile.getWeatherConditions()) {
mProducedEnergy[counter++] = s * w * mPvSystem.getEfficiency() * mPvSystem.getPanelSurface();
}
}
}
或将mProducedEnergy
更改为List<> mProducedEnergy = new ArrayList<>();
private void calculateProducedEnergy() {
for (Integer s: mWeatherProfile.getSunshine()) {
for (Double w: mWeatherProfile.getWeatherConditions()) {
mProducedEnergy.add(s * w * mPvSystem.getEfficiency() * mPvSystem.getPanelSurface());
}
}
}