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;
}
2.
Put the following code in order to create a method that will find the first 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;
boolean found = false;
---
for (int i = 0; i<20&& !found; i++) {
---
if (arr[i] == target) {
---
loc = i;
found = true;
---
}
}
---
return loc;
}
3.
Put the following code in order to create a method that will count the number of occurrences of a target value and return the count.
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;
}