Menu
Question Index
...

What will be the output of the following program?

class RecursiveFor
{
    public static void main(String[] args)
    {
        int out = -15;
        for (int i = 5; i < 7; i++)
        {
            for (int j = 8; j >= 6; j--)
            {
                if (i == j) break;
                if (i > j)
                {
                    out += main(i, j);
                }
                else
                {
                    out += main(j, i);
                }
            }
        }
        System.out.println("out = " + out);
    }

    private static int main(int a, int b)
    {
        if (a + b == 0)
        {
            return 2;
        }
        return a + main(a - 1, b);
    }
}


out = 84
out = 0
out = -84
out = 5
Compilation Error

Doubts

Problems

Topic: Recursive 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