Advertisement
Deianov

Recursive Fibonacci

Feb 15th, 2019
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. // 03. Recursive Fibonacci
  2.  
  3. package MoreExercise;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class M03 {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         int number = Integer.parseInt(scanner.nextLine());
  11.         System.out.println(fibonacci(number));
  12.     }
  13.     private static int fibonacci(int n)  {
  14.         if (n < 2) return n;
  15.         return fibonacci(n - 1) + fibonacci(n - 2);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement