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;
- }
- }
- }
import java.util.Scanner; class Fibonacci_Test { 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 org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertEquals;// TODO: Replace examples and use TDD by writing your own testsclass SolutionTest {@Testvoid testSomething() {int n = 6;long start = System.currentTimeMillis();Long fibo = Fibonacci.calcFibo(n);long end = System.currentTimeMillis();System.out.println("Fibonacci(" + n + ") = "+ fibo + " and takes " +(end - start) + "ms");- import java.util.Scanner;
- class Fibonacci_Test
- {
- 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;
- }
- }