Menu
Topics Index
...
`

Recursive Method597


If you need explanation Read this topic

If you need Answer Take test on this topic

Recursive Method597
What will be the output of the following program?
class Recursion
{
    public static void main(String[] args)
    {
        int ma = 35;
        int in = 67;
        int sta = recurse(ma, in);
        System.out.println("static = " + sta + "tic");
    }

    public static int recurse(int pub, int lic)
    {
        if (pub % 13 == 0)
        {
            return pub + lic;
        }
        return recurse(++pub, lic / 2);
    }
}

A. static = 41tic
B. static = 47tic
C. static = 43tic
D. Compilation Error
E. Throws StackOverflowError
Topic: Recursive 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.

Option c is the answer. For every recursive call pub incremets by 1 and lic reduces to half. For the last iteration the value of pub will be 39 and the value of lic will be 4. Finally the recurse function returns 43 to mai function and it primts the output.

Posted by Ramya Bonagiri    2014-03-19 03:48:03


Ans is c the value of sta will be.41 in the recur function and ptints

Posted by Bharath Yelchuri    2014-03-19 04:08:36


Congratulations Ramya Bonagiri. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-20 04:17:31


Thank you!!!! :D @merit campus

Posted by Ramya Bonagiri    2014-03-20 05:40:48


© meritcampus 2019

All Rights Reserved.

Open In App