Page 337 - AP Computer Science A, 7th edition
P. 337
To call this method (in the same class that it’s defined):
int[] array;
< c ode to initialize array >
int min = findMin(array);
Example 2
Array elements modified:
/∗∗ Add 3 to each element of array b. ∗/ public static void changeArray(int[] b)
{
for (int i = 0; i < b.length; i++) b[i] += 3;
}
To call this method (in the same class):
int[] list = {1, 2, 3, 4}; changeArray(list);
System.out.print(“The changed list is “); for (int num : list)
System.out.print(num + “ ”);
The output produced is
The changed list is 4 5 6 7
Look at the memory slots to see how this happens:
When an array is passed as a parameter, it is possible to alter the contents of the array.