public static int[] allIndices(int[] arr, int si, int data, int count) {
if (si == arr.length)
return new int[count];
int[] indices = null;
if (arr[si] == data) indices = allIndices(arr, si + 1, data, count + 1);
else allIndices(arr, si + 1, data, count);
if (arr[si] == data) if (indices != null) {
indices[count] = si; //TODO: Here is the error.
}
return indices;
}
public static void main(String[] args) {
System.out.println(Arrays.toString(allIndices(new int[]{3, 8, 1, 8, 8, 4}, 0, 8, 0)));
}