Menu
Question Index
...

What will be the output of the following program?

public class SumOfNaturalNumbers
{
    public static void main(String args[])
    {
        int range = 20;
        System.out.print(sumOfNaturalNumbers(range));    
    }
    private static int sumOfNaturalNumbers(int range)
    {
        int sum = 0;
        if (range == 1)
            return 1;
        sum = range + sumOfNaturalNumbers(range - 1);
        return sum;
    }
}


155
312
190
210
Compilation Error or Runtime 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