Java Modifying Elements in a foreach

前端 未结 4 1170
迷失自我
迷失自我 2020-12-04 02:18

I\'m learning Java on my own; and therefore the code below has no function other than for learning/testing.

Essentially I\'m trying to modify the elements of an Inte

4条回答
  •  借酒劲吻你
    2020-12-04 02:36

    int counter = 0;
    for(int x : copyArray)
    {
            x /= 2;
            copyArray[counter++] = x;
    }
    

    Your program just modified the value of variable x , not the values within the blocks of array copyArray

提交回复
热议问题