Pass as argument - a copy of the reference to the instantiated array is passed to the method. This means that any changes made to the array elements inside the method are persistent. The one exception to this is if you assign the argument to reference a different array in memory.
Q21: Put the following code in order to create a method that will find the last occurrence of a target value and return the index of where that value is located.
public static int find (int [] arr, int target) {
---
int loc = -1;
---
for (int i = 0; i < arr.length; i++) {
---
if (arr[i] == target)
---
loc = i;
---
}
---
return loc;
}
public static int count (int [] arr, int target) {
---
int num = 0;
---
for (int i = 0; i < arr.length; i++) {
---
if (arr[i] == target)
---
num++;
---
}
---
return num;
}