Created
November 5, 2010 13:22
-
-
Save jasongorman/664146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FibonacciGenerator { | |
public int getNumberAtPosition(int positionInSequence){ | |
if(positionInSequence > 1){ | |
return getNumberAtPosition(positionInSequence - 1) + | |
getNumberAtPosition(positionInSequence - 2); | |
} | |
return positionInSequence; | |
} | |
public int[] getSequenceOfLength(int length){ | |
if(length < 8 && length > 50){ | |
throw new IllegalArgumentException(); | |
} | |
int[] sequence = new int[length]; | |
for(int index = 0; index < length; index++){ | |
sequence[index] = getNumberAtPosition(index); | |
} | |
return sequence; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment