-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathLucasSeries.java
More file actions
30 lines (25 loc) · 789 Bytes
/
LucasSeries.java
File metadata and controls
30 lines (25 loc) · 789 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
public class LucasSeries extends ThreadSubscriber implements ObserverTest {
double input;
@Override
public void notifySubscriber() {
input = topic.getInput();
System.out.println("Lucas Series of " + (int) input + " = " + execute());
}
@Override
public String execute() {
if ((int) input == 0)
return "2";
int fn_2 = 2, fn_1 = 1;
for (int i = 2; i <= (int) input; ++i) {
int temp = fn_1;
fn_1 = fn_1 + fn_2;
fn_2 = temp;
}
return String.valueOf(fn_1);
}
@Override
public Boolean test() {
input = 5;
return execute().equals("11");
}
}