-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathLucasSeriesSub.java
More file actions
39 lines (37 loc) · 1.11 KB
/
LucasSeriesSub.java
File metadata and controls
39 lines (37 loc) · 1.11 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
import java.util.ArrayList;
public class LucasSeriesSub implements ISubscriber {
@Override
public void notifySubscriber(String input) {
int numOfTerms = Integer.parseInt(input);
ArrayList<Integer>lucesResult = new ArrayList<Integer>();
int temp1 = 2 , temp2 = 1;
int j = 0 , temp = 0;
if(numOfTerms == 1)
{
lucesResult.add(temp1);
}
else if (numOfTerms == 2)
{
lucesResult.add(temp1);
lucesResult.add(temp2);
}
else if (numOfTerms > 2)
{
lucesResult.add(temp1);
lucesResult.add(temp2);
for(int i = 2 ; i < numOfTerms ; i++)
{
temp1 = lucesResult.get(j);
temp2 = lucesResult.get(++j);
temp = temp1 + temp2;
lucesResult.add(temp);
}
}
else
{
System.out.println("Not invalid Input");
System.exit(0);
}
System.out.println("The Series is : " + lucesResult);
}
}