Re: need help with loops plz

Code :

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Input number of fib numbers to finds: ");
int end = input.nextInt();
System.out.println("1\n1");
int fib1 = 1;
int fib2 = 1;
for(int i = 3; i < end; i++)
{
int temp = fib1+fib2;
System.out.println(temp);
fib1 = fib2;
fib2 = temp;
}
}

Re: need help with loops plz

i've red a book exercise and it describes fibonacci , ( a pare of rabbit that matures in 2 months and capabale of reproducing every after maturity), is that exactly what fibonacci system is?

Re: need help with loops plz

mm... rabbits don't normally reproduce via the fibonacci sequence. Instead, they reproduce exponentially (actually, to be more precise the produce logarithmically, at some point their population will be limited by some factors). Neither of these follows the fibonacci sequence.

The fibonacci sequence is this:

Start with 1 and 1.

Add the terms: 1+1 = 2 is the next term.

Keep adding the 2 previous terms for the next term.

1+2=3

2+3=5

3+5=8

....

In fact, the fibonacci grows at a much faster rate than most functions (even exponentials). I think the one exponential that does grow faster than fibonacci is x^x (don't take my word for it, though). I'm not sure if fibonacci grows faster than factorials, either.

Re: need help with loops plz

i didnt post the exact details.. here it is..

"suppose we have a pair of rabbits (assuming that these rabbits dont die) a pair of rabbits will mature in 2 months. and they are capable of reproducing another pair after maturity(after 2 months)

is this a fibonacci sequence?