fork(2) download
  1. class Fibonacci {
  2. public static long fibonacci(int n) {
  3. return n < 2 ? n : fibonacci(n - 2) + fibonacci(n - 1);
  4. }
  5.  
  6. public static void main(String[] args) {
  7. for (int i = 0; i <= 10; i++) {
  8. System.out.println("Fibonacci(" + i + ") = " + fibonacci(i));
  9. }
  10. }
  11. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Fibonacci(0) = 0
Fibonacci(1) = 1
Fibonacci(2) = 1
Fibonacci(3) = 2
Fibonacci(4) = 3
Fibonacci(5) = 5
Fibonacci(6) = 8
Fibonacci(7) = 13
Fibonacci(8) = 21
Fibonacci(9) = 34
Fibonacci(10) = 55