d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > 25 Fg For Some Basic Java Help
Add Reply New Topic New Poll
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Feb 1 2013 06:57pm
Quote
The first 12 Fibonacci numbers are:

1 1 2 3 5 8 13 21 34 55 89 144

Write a piece of code that uses a for loop to compute and print the first 12 Fibonacci numbers. (You may include other code, such as declaring variables before the loop, if you like. 


I can't use any code beyond what we've learned in class. That means it can only include some of the following (just as examples):

loops, nested loops, declaring variables, and using x += (number) for sums

Similar to this:
int n = 1;
for (int i = 1; i <= 10; ++i) {
System.out.print(n + " ");
n += i + i + 1;
}
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Feb 1 2013 08:17pm
Nevermind I figured it out!
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Feb 1 2013 09:48pm
ur prof is a dick for making you do this w/o teach recursion first :p
Member
Posts: 4,980
Joined: Jan 16 2010
Gold: 0.00
Warn: 20%
Feb 2 2013 02:12am
Quote (Eep @ 2 Feb 2013 05:48)
ur prof is a dick for making you do this w/o teach recursion first :p


It is a classic recursion example, but he may want them to solve the same exercise by recursion later, showing the differences between the two methods.
Member
Posts: 14,386
Joined: Dec 5 2006
Gold: 0.00
Feb 7 2013 06:57pm
easy as fock

do you go to UCSD?
Member
Posts: 5,151
Joined: Oct 10 2007
Gold: 40.00
Feb 7 2013 06:58pm
easy as fock

do you go to UCSD?
Member
Posts: 26,204
Joined: Jun 19 2007
Gold: 3.39
Feb 8 2013 03:09am
easy as fock

do you go to UCSD?
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll