Calculate fibonacci recursively - Java Algorithm

Java examples for Algorithm:Number

Description

Calculate fibonacci recursively

Demo Code

public class Main {
  public static void main(String args[]) {
    int nums = fibonacci(8);
    System.out.println(nums);/*  w  w w.  j a va2 s  . c o m*/
  }

  static int fibonacci(int n) {
    if (n <= 1)
      return 1;
    return fibonacci(n - 1) + fibonacci(n - 2);
  }
}

Related Tutorials