Results 1 to 6 of 6
  1. #1
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Print 20 #s of Fib using Dynamic A

    I need to print the first 20 numbers of the Fibonacci sequence using a dynamic array.

    Here's the thing I need to convert.

    Java Code:
    ublic class Fibinocci1 {
    	public static void main(String [] ars) {
    	int[] numbers;
    	numbers = new int[20];
    	numbers[0] = 0;
    	numbers[1] = 1;
    	System.out.println(numbers[0]);
    	
    	for(int i = 2;i < 20; i++) {
    		numbers[i] = numbers[i-2] + numbers[i-1];
    		System.out.println(numbers[i]);
    		}
    	}
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Print 20 #s of Fib using Dynamic A

    I think your code is fine but also print out numbers[1].

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: Print 20 #s of Fib using Dynamic A

    I need to use a dynamic array instead of a single array.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Print 20 #s of Fib using Dynamic A

    Quote Originally Posted by Army View Post
    I need to use a dynamic array instead of a single array.
    How 'dynamic' do you want it to be? Should it wiggle its tail all the time?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: Print 20 #s of Fib using Dynamic A

    Like as in array[][]...

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Print 20 #s of Fib using Dynamic A

    Quote Originally Posted by Army View Post
    Like as in array[][]...
    What should it contain? Really, all you need is a single dimension array (as your code does) and fill it 'dynamically' (as your code does).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Dynamic Casting
    By Thorton in forum Advanced Java
    Replies: 30
    Last Post: 01-12-2010, 09:01 PM
  2. Dynamic GUI
    By ike2u in forum New To Java
    Replies: 4
    Last Post: 08-08-2009, 02:50 AM
  3. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  4. Dynamic DecimalFormatter
    By felixtfelix in forum New To Java
    Replies: 0
    Last Post: 03-17-2008, 04:16 PM
  5. Help for dynamic classes
    By Bender in forum Advanced Java
    Replies: 1
    Last Post: 12-19-2007, 08:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •