print array position this prints the value

import java.util.ArrayList;

import java.util.Arrays;

public class SumSet {

static void sum_up_recursive(ArrayList numbers, int target, ArrayList partial) {

int s = 0;

for (int x: partial) s += x;

if (s == target)

System.out.println("input("+Arrays.toString(partial.toArray())+")="+target);

if (s >= target)

return;

for(int i=0;i
ArrayList remaining = new ArrayList();

int n = numbers.get(i);

for (int j=i+1; j
ArrayList partial_rec = new ArrayList(partial);

partial_rec.add(n);

sum_up_recursive(remaining,target,partial_rec);

}

}

static void sum_up(ArrayList numbers, int target) {

sum_up_recursive(numbers,target,new ArrayList());

}

public static void main(String args[]) {

Integer[] numbers = {5,5,15,10};

int target = 15;

sum_up(new ArrayList(Arrays.asList(numbers)),target);

}

}...

Read More »

By: StackOverFlow - 7 days ago

Related Posts