We exploit the following recursive definition of the sum between two non-negative integers:

Implementation:

public static int sum(int x, int y) { if (y == 0) return x; else return 1 + sum(x, y-1); }