Skip to content

Instantly share code, notes, and snippets.

@stunstunstun
Created March 31, 2014 13:05
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 stunstunstun/9891854 to your computer and use it in GitHub Desktop.
Save stunstunstun/9891854 to your computer and use it in GitHub Desktop.
public class Fibo {
private static final int MAX_COUNT = 10;
private static List<Integer> numbers = new ArrayList<Integer>();
public static void main(String[] args) {
// Get
for(int i = 0 ; i < MAX_COUNT ; i++) {
numbers.add(fibo(i));
}
// Print
Iterator<Integer> iter = numbers.iterator();
while(iter.hasNext()) {
Integer n = (Integer) iter.next();
System.out.println(n);
}
}
private static int fibo(int number) {
if(number == 0 || number == 1)
return number;
return fibo(number - 2) + fibo(number - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment