Menu
Question Index
...

What will be the output of the following program?

public class Equation {
    public static void main(String args[]) {
        int t = 1;
        String s = "2";
        int N, A, B, C, sum;
        for (int i = 0; i < t; i++) {
            N = A = B = C = Integer.parseInt(s);
            A++;    B++;    C++;
            sum = (int) (get(N) + get(N - A - B) + get(N - B - C) + get(N - A - C) - get(N - A));
            System.out.println("Sum = " + sum);
        }
    }
    public static long get(long n) {
        if (n < 0)
            return 0;
        return ((n + 3) * (n + 2) * (n + 1)) / 6;
    }
}


Sum = 9
Sum = 10
Sum = 16
Sum = 42
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Collections - Utility Classes In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App