/// Returns the sum of an array, recursively.
int total(int[] numbers) {
    return total(numbers, 0);
}

/// Returns the sum of the items from index start to the end.
int total(int[] numbers, int start) {
    if (start == numbers.length) {
        return 0;
    }
    return numbers[start] + total(numbers, start + 1);
}

void main() {
    IO.println(total(new int[] {1, 2, 3, 4, 5}));
}

// From Groundwork, chapter 12 (ch12-recursion-and-problem-solving), box 4.
// This example is from Groundwork, licensed CC BY-NC-SA 4.0.
// Run with: java ch12_04.java
