Advertisement
vp0415

lec4.4

Oct 31st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Fibonacci {
  4.     public static long fib(long number)
  5.     {
  6.         if(number <= 1)
  7.         {
  8.             return number;
  9.         }
  10.         else
  11.         {
  12.             return fib(number-1) + fib(number-2);
  13.         }
  14.     }
  15.  
  16.     public static void main(String[] args) {
  17.         Scanner input = new Scanner(System.in);
  18.         System.out.println("Enter number: ");
  19.         int n = input.nextInt();
  20.         System.out.println("Fibonacci of " + (n)+ " is: ");
  21.         for(int counter = 0; counter < n; counter++)
  22.         {
  23.             System.out.println(fib(counter));
  24.         }
  25.  
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement