Menu
Question Index
...

What will be the output of the following program?

public class AllTheBest {
    public static void main(String[] str) {
        boolean result;
        int ary[] = {2, 4, 8};
        result = groupSum(0, ary, 10);
        System.out.print(result + ", ");
        result = groupSum(0, ary, 9);
        System.out.print(result + ", ");
        result = groupSum(0, ary, 14);
        System.out.println(result);
    }
    public static boolean groupSum(int start, int[] nums, int target) {
        if (start >= nums.length)
            return (target == 0);
        if (groupSum(start + 1, nums, target - nums[start]))
            return true;
        if (groupSum(start + 1, nums, target))
            return true;
        return false;
    }
}


true, false, false
true, false, true
true, true, true
false, false, false
Compilation Error or Runtime Error

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App