增量逻辑无法正常工作

时间:2014-09-24 12:20:49

标签: java for-loop

我必须根据外部循环增加内部循环,但我的逻辑失败。

int size = currencyList.size();

for (int i=0, j=1; i<size; i++) {
    CurrencyVO currencyVO = currencyList.get(i);
    obj1[i+2] = currencyVO.getStrDerivedRefDT();
    // CurrencySetupVO cureccyCodeDes = currencyExchList.get(k);

    //if (i==0)
    obj3[0]=currencyVO.getStrCurrencyCode();
    //if (i==1)
    obj3[1]= currencyVO.getStrCurrencyDesc();
    //if (k<size) {
    obj3[i+2]=currencyVO.getStrExchRate();
    //}
    data.put(j,obj3);
    data.put(0,obj1);
    if (i==31) {//***Here for every i=31,62,93 etc J has to increment***
        j++;
    }
}

我该如何实现?

2 个答案:

答案 0 :(得分:6)

  

对于每个i = 31,62,93等,j必须增加

然后你的逻辑应该是

 if(i!=0 && i%31 ==0){//***Here for every i=31,62,93 etc J has to increment***
                j++;
            }

该%是modulo operator

答案 1 :(得分:1)

如果你想为每个i = 31,62增加J ...... 然后初始化j = 0并检查

if(i!=0 && i%31 == 0)
{
j++;  //j will increase for every i=31,62,.....
}