I am trying to add array list values in dynamic manner of all combinations using for loop . For example adding two elements combination in an array can be done by nested loop. Similarly 3,4,5,6,7,8 like that combination addition is need dynamic for loop generation. What can I do?
static int birthday(List<Integer> s, int d, int m) {
int l=s.size();
int count=0;
int a[]=new int[l];
for (int x=0; x<l; x++){
a[x]=s.get(x);
}
if(m==2){
for (int i=0; i<l; i++){
for (int j=i+1; i<l; i++){
if(a[i]+a[j]==d){
count++;
}
}
}
}
else if(m==1){
count++;
}
return count;
}
Above code is for 1 and 2 combinations and for all the 3,4,...10. I want to generate dynamic for loop. Please give solution.
O(n^300)