public class GroupSum0 { public static boolean findgroup(int[] values, int pos, int sum) { if(sum == 0) return true; if(pos >= values.length) return false; int val = values[pos]; boolean res = findgroup(values, pos+1, sum - val); if(res) return true; return findgroup(values, pos+1, sum); } public static boolean findgroup(int[] values, int sum) { return findgroup(values, 0, sum); } public static void main(String[] args) { assert(findgroup(new int[]{1,3,5,2,7},9) == true); assert(findgroup(new int[]{11,3,5,20,7},109) == false); for(int n=0;n<25;n++) System.out.printf("%d -> %s%n", n, findgroup(new int[]{11,3,5,20,7},n)); } }