give a code for fibonacci numbers

Solutions on MaxInterview for give a code for fibonacci numbers by the best coders in the world

showing results for - "give a code for fibonacci numbers"
Andrea
03 Apr 2018
1import java.util.Scanner;
2
3public class fibonaci {
4    public static void main(String[] args) {
5        System.out.println ("Enter number of terms in the Series");
6        Scanner sc = new Scanner (System.in);
7        int n = sc.nextInt ();
8
9        for (int i = 0; i < n; i++) {
10            System.out.print (fibo (i) + " ");
11        }
12    }
13
14    public static int fibo(int i) {
15        if (i == 0) {
16
17            return 0;
18        } else if (i == 1) {
19            return 1;
20        } else {
21            return fibo (i - 1) + fibo (i - 2);
22        }
23    }
24}
25