-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
43 lines (36 loc) · 1.06 KB
/
Copy pathMain.java
File metadata and controls
43 lines (36 loc) · 1.06 KB
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
35
36
37
38
39
40
41
42
43
package fibonacciWithRecursive;
import java.util.Scanner;
/**
* @author Fatih ARI - 21.08.2021
*
* A program that finds the Fibonacci series with recursive function, whose number of elements is taken from the user , is designed.
*
*/
public class Main {
private static int f(int index)
{
if(index== 1)
return 0;
else if(index == 2)
{
return 1;
}
return f(index-1)+ f(index-2); //f(2) = f(0)+f(1)
}
public static void main(String[] args) {
clearScreen();
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = input.nextInt();
input.close();
for (int i = 1; i <= number; i++) {
System.out.print(f(i)+ " ");
}
System.out.println();
}
//It is used for console screen cleaning in Java.
public static void clearScreen() {
System.out.print("\033[H\033[2J");
System.out.flush();
}
}