See what this method does:
public static void x(int array[], int y)
{
array[y] = array[y - 1] * 2;
}
It takes a value in the index y-1
, multiplies it by 2
, then assigns this result to the index y
.
Starting array: {1,2,3,4}
A call with v[2] - 1
takes a value in the index 2
(which 3
) and subtracts 1
, so we have y = 2
.
, , 1
(y-1
), 2
, 2
, 4
2
(y
).
: {1,2,4,4}
v[3] - 1
3
( 4
) 1
, y = 3
.
, , 2
(y-1
), 4
, 2
, 8
3
(y
).
: {1,2,4,8}