Answers for "give a code for fibonacci numbers"

1

give a code for fibonacci numbers

import java.util.Scanner;

public class fibonaci {
    public static void main(String[] args) {
        System.out.println ("Enter number of terms in the Series");
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt ();

        for (int i = 0; i < n; i++) {
            System.out.print (fibo (i) + " ");
        }
    }

    public static int fibo(int i) {
        if (i == 0) {

            return 0;
        } else if (i == 1) {
            return 1;
        } else {
            return fibo (i - 1) + fibo (i - 2);
        }
    }
}
Posted by: Guest on March-16-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language