Menu
Topics Index
...
`

Equation


If you need explanation Read this topic

If you need Answer Take test on this topic

Equation
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;
    }
}

A. Sum = 9
B. Sum = 10
C. Sum = 16
D. Sum = 42
E. Compilation Error or Runtime Error
Topic: Java Collections - Utility Classes In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B...(N=2,A=3,B=3,C=3) ..as get(N) returns 10 and remaining all get methods return 0 ..the sum is 10

Posted by Krishna Sai    2013-05-28 12:35:28


ans:b ithe sum value takes increments of the strring values parses them to integer it return 10 as sum and gets of return as 0.

Posted by Karteek Paruchuri    2013-05-28 12:41:53


Congratulations Karteek Paruchurii. You are daily dose winner. Please send us your mobile details and we will process the recharge after considering the new likes.

Posted by Merit Campus    2013-05-29 03:17:04


Got the rc thank you

Posted by Karteek Paruchuri    2013-05-29 14:06:15


© meritcampus 2019

All Rights Reserved.

Open In App