Advertisement
fahimkamal63

Fibonacci Series

May 25th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. /*
  2.  * Fibbonacci with recursion
  3.  * Date : 25.05.19
  4.  */
  5. import java.util.Scanner;
  6. public class Fibbonacci_With_Recursion {
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         System.out.print("Enter range: ");
  10.         System.out.println();
  11.         int n = input.nextInt();
  12.         for(int i = 0; i < n; i++) {
  13.             System.out.print(fibo(i) + " ");
  14.         }
  15.         input.close();
  16.        
  17.     }
  18.     static int fibo(int n) {
  19.         if(n < 2) return n;
  20.         return fibo(n-1) + fibo(n-2);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement