public class Main
{
public static int[] Find_all_indices(int arr[] , int find_no , int count ,int si){
if(si == arr.length){
int[] base = new int[count];
return base ;
}
int[] result_arr = null;
if(arr[si] == find_no){
result_arr = Find_all_indices(arr , find_no , count+1 , si+1);
}
else{
result_arr = Find_all_indices(arr , find_no , count , si+1);
}
if(arr[si] == find_no){
result_arr[count] = si ;
}
return result_arr ;
}
public static void main(String[] args) {
int arr[] = {3 , 8 , 1 , 8 , 8 , 4};
int find_no = 8 ;
int count = 0 ;
int si = 0 ;
int[] ans = Find_all_indices(arr , find_no , 0 , 0);
for(int i = 0 ; i < ans.length ; i++){
System.out.print(arr[i]+" ");
}
}
}
OUTPUT - 3 , 8 , 1
Sir when I am running my code it is giving me this output I tried debugging also but couldn’t find the issue and sir please tell me the use of base array .