1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class _Math { static int[] fibonacci_series(int size){ if(size == 0) return new int[0]; if(size == 1) return new int[]{1}; if(size == 2) return new int[]{1,1}; int[] array = new int[size]; array[0] = 1; array[1] = 1; for (int i = 2; i < array.length; i++) array[i] = array[i - 1] + array[i - 2]; return array; } } |
styled using hilite.me
No comments:
Post a Comment