forked from NaNaDi/Programming_Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
34 lines (28 loc) · 932 Bytes
/
Copy pathFibonacci.java
File metadata and controls
34 lines (28 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
// System.out.println("Enter the number:");
// Scanner scan = new Scanner(System.in);
// int a = scan.nextInt();
// printFibonaci(a);
printFibonaci(8);
}
private static void printFibonaci(int range) {
for (int start = 0; start < range; start ++) {
System.out.println(initFibonaci(start));
System.out.print(" ");
}
}
private static int initFibonaci(int range) {
switch (range) {
case 0:
return 0;
case 1:
return 1;
default:
return initFibonaci(range - 1) + initFibonaci(range - 2);
}
}
//todo: implement a recursive function which takes an integer value as inputs and outputs the corresponding Fibonacci number.
//if you don't know what Fibonacci numbers are you can read it here: https://en.wikipedia.org/wiki/Fibonacci_number
}