第二个循环(for (int j = years[i].xrateValue.size ()-1; j >= 0; j--))是从数组(year[i])中检索每个年份的所有xrate值。请你有什么办法,我可以只返回数组中每一年的xrate值。例如,1990年有Xrate 2,5,6,5.6,1991年有Xrate 3,6.7,5,8,1.4。这个循环应该只返回1990年的Xrate值,然后是1991年,以此类推。
for (int i=0; i<years.length; i++)
{
//code to display each year
for (int j = years[i].xrateValue.size ()-1; j >= 0; j--)
{
float xrate = (float)(years[i].xrateValue.get(j));
float barHeight = map(xrate, 0, mathMax, 0, 80); //adjust rect size
float bX = sX+2;
float bY = sY + 105 - barHeight;
float bW = 105 / years.length;
strokeWeight(0.9);
stroke(10);
fill(255, 8, 8);
if (xrate >= 71)
{
fill(2, 152, 48);
} else if ((xrate >= 51) && (xrate <= 70))
{
fill(255, 217, 19);
}
rect(i+i+i+bX, bY, bW, barHeight);
}
}
for(int i : [listname]){
for(int j = i; j > 0; j--){
// your code
}
}
这重复了一个重复,每次重复的时候都会多重复1次(哇,真让人糊涂。只要读一遍就能明白了。)。