If i get it right you are looking for a subset of that array with a maximal product under a given limit and the output to be something like
arr[1]*arr[5]*arr[6]*arr[10]
is the subset with the max. product.
In order to do this you need first to get the powerset of your array, i.e. all possible subsets of your array and calculate the product of each subset checking if it is the maximal under a given limit. Beleow is an example how to do so:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class NewClass {
public static void main(String[] args) {
Integer[] array = {-5,1,-1,0,10,-10,9,-2,1001};
List<Integer> list = Arrays.asList(array);
Integer limit = 1000;
List<List<Integer>> powerset = getPowerset(list);
List<Integer> maxProdList = getMaxProduct(powerset,limit);
Integer prod =1;
for(Integer i : maxProdList){
prod*=i;
}
System.out.println("List: " + maxProdList );
System.out.println("max product: " + prod );
}
//returns all possible subsets [[-5],[-5,1,9],[1,-1,1001][-5,1,-1,0,10] ... and so on]
// see also http://stackoverflow.com/questions/1670862/obtaining-a-powerset-of-a-set-in-java
public static List<List<Integer>> getPowerset(Collection<Integer> list) {
List<List<Integer>> ps = new ArrayList<>();
ps.add(new ArrayList<>());
for (Integer item : list) {
List<List<Integer>> newPs = new ArrayList<>();
for (List<Integer> subset : ps) {
newPs.add(subset);
List<Integer> newSubset = new ArrayList<>(subset);
newSubset.add(item);
newPs.add(newSubset);
}
ps = newPs;
}
return ps;
}
public static List<Integer> getMaxProduct(List<List<Integer>> listOfLists, Integer limit){
List<Integer> listOfMax = new ArrayList<>();
Integer max = 1;
for(List<Integer> list : listOfLists){
Integer prod =1;
for(Integer i : list){
prod*=i;
}
if(prod>max && prod<=limit){
max=prod;
listOfMax = list;
}
}
return listOfMax;
}
}