Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Fibonacci {
- public static long fib(long number)
- {
- if(number <= 1)
- {
- return number;
- }
- else
- {
- return fib(number-1) + fib(number-2);
- }
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter number: ");
- int n = input.nextInt();
- System.out.println("Fibonacci of " + (n)+ " is: ");
- for(int counter = 0; counter < n; counter++)
- {
- System.out.println(fib(counter));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement