Skip to content
Quiz · Methods · lesson 8 of 8

Quiz — a recursive sum

What does the program print?

JAVA
public class Main {
    static int f(int n) {
        return n == 0 ? 0 : n + f(n - 1);
    }
    public static void main(String[] args) {
        System.out.println(f(4));
    }
}