-2

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?

jayden orr
  • 11
  • 3
  • 2
    Please post your code. Have you tried anything? is there any problems with your code you want help with? – ItamarG3 Nov 15 '16 at 18:45
  • by dynamic array, you mean an ArrayList ? Or really coding yourself a dynamic array ? http://stackoverflow.com/questions/2426671/variable-length-dynamic-arrays-in-java – alexbt Nov 15 '16 at 18:46
  • I really don't know where to start. Here is my example of a dynamic array. https://curriculum.kcdistancelearning.com/courses/PROG2s-HS-A08/s/unit3/resources/images/JV_3.3.9.1.JPG and https://curriculum.kcdistancelearning.com/courses/PROG2s-HS-A08/s/unit3/resources/images/JV_3.3.9.2.JPG – jayden orr Nov 15 '16 at 18:51
  • Possible duplicate of [printing the results of a fibonacci series](https://stackoverflow.com/questions/18563321/printing-the-results-of-a-fibonacci-series) – Mariano Zorrilla Jun 19 '18 at 18:05

1 Answers1

0

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;
            arr.add(temp);
            i = j;
            j = temp;
            s++;
        }

        for(Integer v : arr)
            System.out.print(v+" ");
    }
}
Rehan Shikkalgar
  • 1,029
  • 8
  • 16
  • Is that a dynamic array? Sorry, I am just starting Java. – jayden orr Nov 15 '16 at 18:55
  • check this site for more information - http://www.javatpoint.com/ArrayList-in-collection-framework – Rehan Shikkalgar Nov 15 '16 at 18:58
  • Thank you guys so much! I searched around but couldn't find any info about dynamic arrays so that really helps. – jayden orr Nov 15 '16 at 19:00
  • I know I am going to get in trouble, but I just started this account today and I just got a message that I can't ask another question for 2 days because my question got voted down! I am in 8th grade I am trying to do a a senior(12th grade) Java course and I have a lot of questions so can you guys just make my question marker at 0 so I can ask more questions? – jayden orr Nov 15 '16 at 19:03