Recursive Array Search
What is printed when the program is executed?
public class FirstIndex {
public static int findFirstIndex(int[] arr, int index, int target) {
if(index == arr.length) return -1;
if(arr[index] == target) return index;
return findFirstIndex(arr, index + 1, target);
}
public static void main(String[] args) {
int[] arr = {5, 7, 9, 7, 3};
System.out.println(findFirstIndex(arr, 0, 7));
}
}
A
0
B
-1
C
1
D
3
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | deltasmpserver | 0 | 2 | 0m 00s | -20 |
| #2 | theofanusmischa | 0 | 1 | 1m 22s | -92 |
| #3 | bommasam000 | 2 | 4 | 14m 14s | -674 |
Items per page:
10
1 – 3 of 3
APFIVE