public static void main(String[] args) {
    int[] nums = {1,2,3,4,5,6,7,8,9};
    //method(nums, 10);

    List<Integer> list = new LinkedList<Integer>();
    System.out.println(list);
    int sum = 10;
    method(nums, sum, list, -1);

}

private static void method(int[] nums, int sum, List<Integer> list, int index){
    if(sum == 0){
        for(int i : list){
            System.out.printf("%d ", i);
        }
        System.out.println();
    }else if(sum > 0){
        for (int i = index + 1; i < nums.length; i++) {
            list.add(nums[i]);
            method(nums, sum - nums[i], list, i);
            list.remove(list.size() - 1);
        }
    }
}