Why can’t we write code int his way?
package Section_6;
import java.util.Arrays;
public class Recursion_All_Indices {
public static void main(String[] args) {
int[] arr = new int[] { 3, 8, 1, 8, 8, 1, 7 };
int[] Arr = all_Indices(arr, 0, 8, 0);
display(Arr);
}
public static int[] all_Indices(int[] arr, int si, int d, int count) {
if (si == arr.length) {
int[] base = new int[count];
return base;
}
int[] Arr = null;
if (arr[si] == d) {
Arr[count] = si;
Arr = all_Indices(arr, si + 1, d, count + 1);
} else if (arr[si] != d) {
Arr = all_Indices(arr, si + 1, d, count);
}
// if (arr[si] == d) {
//
//}
return Arr;
}
public static void display(int[] arr) {
int i;
for (i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}