Why does this code return 4 4 rather than 4 1?
I traced the new values[k]
to be 4 through the for-loop, but I understand that int[]
numbers was copied to the original int[]
values array, so did the int[]
numbers change WITH int[]
values through the for-loop?
Is this a rule I'm not aware of?
int[] values = { 1, 3, 1, 3, 1 };
int[] numbers = values;
for (int k = 0; k < values.length; k++)
{
values[k] = k * 2;
}
System.out.print(values[2]);
System.out.print(" " + numbers[2]);