-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacciRange.java
More file actions
38 lines (32 loc) · 932 Bytes
/
FibonacciRange.java
File metadata and controls
38 lines (32 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
35
36
37
38
import java.util.*;
class FibonacciRange {
int start;
int end;
FibonacciRange() {
start = 0;
end = 0;
}
void readValues() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the start and end values for the Fibonacci series:");
start = sc.nextInt();
end = sc.nextInt();
}
int fibonacci(int n) {
if (n == 0) return 0;
else if (n == 1) return 1;
else return (fibonacci(n - 1) + fibonacci(n - 2));
}
void displayFibonacciSeries() {
System.out.println("Fibonacci Series:");
for (int i = start; ; i++) {
if (fibonacci(i) > end) break;
else System.out.println(fibonacci(i));
}
}
public static void main(String[] args) {
FibonacciRange fiboObj = new FibonacciRange();
fiboObj.readValues();
fiboObj.displayFibonacciSeries();
}
}