Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created November 5, 2010 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/664151 to your computer and use it in GitHub Desktop.
Save jasongorman/664151 to your computer and use it in GitHub Desktop.
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