Results 1 to 9 of 9
Thread: help with fibonacci
 01062010, 02:38 AM #1Member
 Join Date
 Jan 2010
 Posts
 2
 Rep Power
 0
help with fibonacci
hello everyone i need big help....
i don't know how to use 'fibonacci' :(
our teacher asked us to make a program that will output how many possible siblings a certain animal can have,
for example if the user input 5 number of kangaroos, we're asked to make a program using fibonacci to output how many possible siblings a 5 kangaroos could have.... she gave us example but i could hardly understand that fibonacci:(
Java Code:import java.io.*; public class FibonacciNum { public static void main (String[]args) throws IOException { BufferedReader dataIN = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a number:"); int num = Integer.parseInt(dataIN.readLine()); fibonacci(num  2) + fabonacci(num1); } }
can someone help me please?
thank you very much
EDIT:
by the way she gave us this formula:
fibonacci(n2)+fibonacci(n1)
fibonacci n = 1
fibonacci o = oLast edited by likemine; 01062010 at 02:40 AM.
 01062010, 03:40 AM #2Senior Member
 Join Date
 Oct 2009
 Location
 California,US
 Posts
 201
 Rep Power
 5
take a look at this
Java Code:import java.io.*; public class FibonacciNum { public static void main (String[]args) throws IOException { //BufferedReader for the class BufferedReader dataIN = new BufferedReader(new InputStreamReader(System.in)); //Asks for a number System.out.println("Enter a number:"); //Here when the system asks for a number. and a user types it. The user //input is a String. So, we need to parse it into a String. int num = Integer.parseInt(dataIN.readLine()); //hmm there doesnt seem to be sense. whats fibnacci(int) here?..Usually you //can do fibonacci through recursion. fibonacci(num  2) + fabonacci(num1); } }
take a look at recursion and fibonacci section. at
recusion
 01062010, 07:01 AM #3Member
 Join Date
 Dec 2009
 Posts
 68
 Rep Power
 0
ill share you mine.. an iterative way.. i had hard time too thinking of how to make a fibonacci program i hope you understand this one...
Java Code:public class FibonacciIterative2 { public static void main(String[] args) { int f1 = 1, f2 = 1, temp; // fibonacci iterating sequence starting in F(N) where N = 3 for (int x = 3; x <= 10; x++) { temp = f1; f1 = f2; f2 = temp + f2; System.out.println(f2); } } }
Last edited by bigj; 01062010 at 07:05 AM.
 01062010, 07:03 AM #4Senior Member
 Join Date
 Oct 2009
 Location
 California,US
 Posts
 201
 Rep Power
 5
 01062010, 07:07 AM #5Member
 Join Date
 Dec 2009
 Posts
 68
 Rep Power
 0
oh sir.. tnx for the quick response to my code... any way.. atleast now i know
fibonacci is more efficient in recursive way... tnx sir!
 01062010, 07:52 AM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,371
 Blog Entries
 7
 Rep Power
 20
 01062010, 08:33 AM #7Senior Member
 Join Date
 Oct 2009
 Location
 California,US
 Posts
 201
 Rep Power
 5
My apologies. Just cross checked. Its the other way around. Iterative is much
more efficient than recursive. Heres an evidence for that.
Recursive vs iterative
Again Sry for the wrong conclusion.
 01062010, 09:15 PM #8Member
 Join Date
 Jan 2010
 Posts
 2
 Rep Power
 0
 01072010, 02:32 AM #9Member
 Join Date
 Dec 2009
 Posts
 68
 Rep Power
 0
Similar Threads

Fibonacci summation problem
By xcallmejudasx in forum New To JavaReplies: 3Last Post: 12012009, 06:28 PM 
help with fibonacci problem
By thekrazykid in forum New To JavaReplies: 4Last Post: 12122008, 10:41 PM 
Printing Fibonacci Numbers
By Java Tip in forum java.langReplies: 0Last Post: 04092008, 06:43 PM 
A Fibonacci printing program
By Java Tip in forum Java TipReplies: 0Last Post: 03282008, 07:26 PM 
Fibonacci Algorithm
By susan in forum New To JavaReplies: 1Last Post: 08072007, 04:25 AM
Bookmarks