daily pastebin goal
24%
SHARE
TWEET

Recursion

a guest May 17th, 2018 106 in 2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. package recursiontest01;
  3.  
  4.  
  5. public class RecursionTest01 {
  6.    
  7.     public static int fibonacci(int n) {
  8.         if(n<=2) {
  9.             return 1;
  10.         }
  11.         else{
  12.             return fibonacci(n-1) + fibonacci(n-2);
  13.         }
  14.     }
  15.    
  16.     public static void main(String[] args) {
  17.         int res = RecursionTest01.fibonacci(10);
  18.         System.out.println(res);
  19.     }
  20. }
RAW Paste Data
Top