Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/main/java/io/zipcoder/Problem2.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
package io.zipcoder;

import java.util.ArrayList;

public class Problem2 {

public String fibon(int n) {
ArrayList <Integer> arrayList = new ArrayList <Integer>();
arrayList.add(0);
arrayList.add(1);

Integer lowerIndex = 0;
Integer higherIndex = 1;
Integer nextInt;

do {
nextInt = arrayList.get(lowerIndex) + arrayList.get(higherIndex);
if (nextInt > n) {
break;
}
arrayList.add(nextInt);
lowerIndex++;
higherIndex++;
} while (true);

return arrayList.toString();

}

}
15 changes: 15 additions & 0 deletions src/test/java/io/zipcoder/Problem2Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

public class Problem2Test {
Problem2 test = new Problem2();

@Test
public void fibonacciIterationTest(){
String expected = "0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144";

String actual = test.fibon(150);

Assert.assertEquals(expected,actual);
}


}