public class Fibonacci { static int calculateFib(int n) { if (n <= 1) { return n; } return calculateFib(n - 1) + calculateFib(n - 2); } public static void main(String args[]) { int n = 9; System.out.println(fib(n)); // 34 // 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 } }