jayden orr jayden orr - 7 months ago 46
Java Question

How to make a Fibonacci series dynamic array java program

I am beginning java and I am trying to make a Fibonacci series with a dynamic array. In my class I was given a Fibonacci series program, and a example of a dynamic array. I am really confused. Can someone show me what this looks like?


try this,

import java.util.*;
public class fib{
    public static void main(String[] args){
        ArrayList<Integer> arr = new ArrayList<Integer>();//ArrayList
        int i = 0, j =1;
        System.out.print(i +" " +j + " ");
        //generate 10 fibonacci numbers
        int s = 0;
        while(s < 10){
            int temp = i + j;
            i = j;
            j = temp;

        for(Integer v : arr)
            System.out.print(v+" ");