×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 3, 2021 7:37 PM
Views: 3975
Tags: recursive
  1.  
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         var test = fib(10);
  7.         System.out.println(test);
  8.     }
  9.  
  10.  
  11.  
  12.  
  13.     public static long fib (final int n){
  14.  
  15.         if(n <= 2){
  16.             return (n > 0) ? 1 : 0;
  17.  
  18.         }else{
  19.             return fib(n-1) + fib(n - 2);
  20.         }
  21.  
  22.     }
  23. }
  24.