class MainDemo{
public static void main(String args[]){
float arrayOne[] = {1, 2, 3, 4,5};
for(int iIndex=0; iIndex<arrayOne.length; iIndex++)
{
arrayOne[iIndex] = iIndex;
iIndex=iIndex+1;
}
for(int iIndex=0; iIndex<arrayOne.length; iIndex++)
{
System.out.println(arrayOne[iIndex]);
}
}
}
为什么会这样输出?
0.0
2.0
2.0
4.0
4.0
而不是
0.0
1.0
2.0
3.0
4.0
最佳答案
因为您只替换原始数组中的索引 0、2 和 4,而 1 和 3 保持不变(每次循环迭代 iIndex 都会增加 2)
关于java - 为什么这段代码的输出是这样的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15216543/