DSA SheetLesson · no judge

CODE DRILL 2 · RUN ONLY

Write it, run it, read the output

This is a scratch drill — your code runs, nothing is graded or recorded. No test cases, no expected output, no verdict.

TASK

Complete the recursive function so its base case returns 0 and each other call adds n to sum(n - 1). Print sum(4), which must produce 10.

Java
Loading editor…

OUTPUT

Sample
10

What a finished answer prints, from the lesson. Nothing has run yet — press Run and this is replaced by your program’s own output.

Previous · Time Complexity Analysis using Recurrence Relations