Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Fibbonacci with recursion
- * Date : 25.05.19
- */
- import java.util.Scanner;
- public class Fibbonacci_With_Recursion {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter range: ");
- System.out.println();
- int n = input.nextInt();
- for(int i = 0; i < n; i++) {
- System.out.print(fibo(i) + " ");
- }
- input.close();
- }
- static int fibo(int n) {
- if(n < 2) return n;
- return fibo(n-1) + fibo(n-2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement