Page 338 - AP Computer Science A, 7th edition
P. 338
Example 3
Contrast the changeArray method with the following attempt to modify one array element:
/∗∗ Add 3 to an element. ∗/
public static void changeElement(int n) { n += 3; }
Here is some code that invokes this method:
int[] list = {1, 2, 3, 4}; System.out.print(“Original array: “); for (int num : list)
System.out.print(num + “ ”); changeElement(list[0]); System.out.print(“\nModified array: “); for (int num : list)
System.out.print(num + “ ”);
Contrary to the programmer’s expectation, the output is