Ad
Code
Diff
  • import java.util.Scanner;
    class Fibonacci
    {
        public static void main(String args[])
        {
            Scanner sc = new Scanner(System.in);
            System.out.println("Enter the number of Iterations:");
            int n = sc.nextInt();
            int a = 0;
            int b = 1;
            System.out.println(a);
            System.out.println(b);
            for(int i = 1;i <=n; i++)
            {
                int c = a + b;
                System.out.println(c);
                a=b;
                b=c;
            }
        }
    }
    • import java.util.HashMap;
    • import java.util.Map;
    • public class Fibonacci {
    • public static long calcFib(int n,int a,int b){
    • return n == 1 ? a : calcFib(n-1,b,a+b);
    • }
    • public static long calcFibo(int n) {
    • return calcFib(n,1,1);
    • }
    • import java.util.Scanner;
    • class Fibonacci
    • {
    • public static void main(String args[])
    • {
    • Scanner sc = new Scanner(System.in);
    • System.out.println("Enter the number of Iterations:");
    • int n = sc.nextInt();
    • int a = 0;
    • int b = 1;
    • System.out.println(a);
    • System.out.println(b);
    • for(int i = 1;i <=n; i++)
    • {
    • int c = a + b;
    • System.out.println(c);
    • a=b;
    • b=c;
    • }
    • }
    • }