我使用以下循环为二维数组赋值,但由于某种原因,i,k和z没有递增;有谁能告诉我为什么?
for(int i=0, k=1, z=0; i<num; i++, k+=3, z+=4)
{
newton[z][0]=a.re[i];
System.out.println("newton ["+z+"]"+"[0]"+ "is " + newton[z][0]);
System.out.println("a.re[0] is "+ a.re[0]);
System.out.println("a.re[1] is "+a.re[1]);
System.out.println("z is "+z);
System.out.println("i is "+i);
System.out.println("num is "+num);
System.out.println("k is "+k);
newton[z+2][0]=a.re[i];
newton[z][1]=a.im[i];
newton[z+2][1]=a.im[i];
newton[z][2]=b.fre[i];
newton[z+2][2]=b.fre[i];
newton[z][3]=b.fim[i];
newton[z+2][3]=b.fim[i];
newton[z+k][4]=c.dre[i];
newton[z+k][5]=c.dim[i];
}
答案 0 :(得分:3)
适合我。您没有在循环中操纵i,k,z的值。因此,您可以通过省略数组newton
的赋值来测试增量是否有效。试试这个:
@Test
public void test() {
for(int i=0, k=1, z=0; i<10; i++, k+=3, z+=4)
{
System.err.println(String.format("%d, %d, %d,", i, k, z));
}
}
输出如下:
0, 1, 0,
1, 4, 4,
2, 7, 8,
3, 10, 12,
...