for (DataType varName : collectionName) - traverses collectionName by iterating from first element to last element storing a copy of each element from collectionName in varName.
When calling a method, pass a reference to an array (usually variable name) as an argument in the method call. (Remember that when passing an array as an argument that changes made by the method to the array are persistent.)
int target = /* some value */ ;
int [] delta = {10, 20, 30, 40, 50, 60, 70, 80, 90};
boolean found = false;
int i, j;
for (i = 0; i < delta.length && !found; i++)
if (delta[i] == target)
found = true;
if (found) {
for (j = i-1; j < delta.length-1; j++)
delta[j] = delta[j+1];
delta[delta.length-1] = -999;
}
Inserts a new value into the first position of the array
Incorrect
Inserts a new value into the middle position of the array
Incorrect
Inserts a new value into the last position of the array
Incorrect
deletes a value from a specific position of the array
int pos = /* some value */;
int [] rho = {10, 20, 30, 40, 50, 60, 70, 80, 90};
for (int m = pos; m < rho.length-1; m++)
rho[m] = rho[m+1];
rho[rho.length-1] = -999;
Inserts a new value into the first position of the array
Incorrect
Inserts a new value into the middle position of the array
Incorrect
Inserts a new value into the last position of the array
Incorrect
deletes a value from a specific position of the array