如何使用数组的索引值遍历ArrayList(正在处理) [英] How to loop over an ArrayList using the index value of an Array (Processing)

查看:4
本文介绍了如何使用数组的索引值遍历ArrayList(正在处理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第二个循环(for(int j=Years[i].xrateValue.Size()-1;j>=0;j--)从数组(Years[i])中检索每一年的所有xrate值。请您知道我如何才能只返回数组中每一年的xrate值。例如,1990年的Xrate为2,5,6,5.6,1991年的Xrate为3,6.7,5,8,1.4。循环应该只返回1990年的Xrate值,然后是1991年的Xrate值,依此类推。

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
    }
}
这将重复重复一次重复,每次重复重复一次(哇,这太令人困惑了。就把它读一遍,直到它明白为止。

这篇关于如何使用数组的索引值遍历ArrayList(正在处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆