On Oct 24, 3:30 pm, Sadia Butt <[email protected]> wrote:
> Thanks everyone for the prompt reply.
>
> Now I know where I was wrong. The problem was that my logic building is not 
> as good as others. If you guys have any suggestions over logic building or 
> other then practice do tell me.
>
> Now I have to work in reverse order of fibonacci.
Elements in an array can be accessed from the end. So we can reverse
the output like:
for(int k=array.length - 1; k >= 0; k--){
 System.out.println(array[k]);
}

What is a fibonacci anyway?
>
> Regards
>
> Sadia Butt
>
> --- On Fri, 10/23/09, Sadia Butt <[email protected]> wrote:
>
> From: Sadia Butt <[email protected]>
> Subject: [java programming] tHANKS to all
> To: [email protected]
> Date: Friday, October 23, 2009, 1:54 PM
>
> Hi all
>
> I am trying to make a program. I saw the program in a book to generate 
> fibonacci series. Now they have something this
>
> code:
>
> class Fibonacci {
>     /** Print out the Fibonacci sequence for values < 50 */
>     public static void main(String[] args) {
>         int lo = 1;
>
>         int hi = 1;
>
>        System.out.println(lo);
>        while (hi < 50) {
>            System.out.println(hi);
>            hi = lo + hi;       // new hi
>            lo = hi - lo;       /* new lo is (sum - old lo)
>                                   that is, the old hi */
>        }
>    }}
>
> Now I understood this but now the exercises in the book is that I have to do 
> backward sequence one & 2nd to save the sequence in an array then display it. 
> I am now focusing in saving the values in an array, but I am unable
>  to solve it.
>
> this is what I modified.
>
> int lo = 1;
>
>         int hi = 1;
>         int array[]= new int [9] ;
>         int i = 0;
> //        System.out.println(lo);
>
>         while (hi < 50) {
>         //    System.out.println(hi);
>             hi = lo + hi;
>             lo = hi - lo;
>             array[i++] = hi;
>
>             array[i++] = lo;
>
>       }
>         for (int k = 0; k < array.length; k++)
>             System.out.println(array[k]);
>     }
>
> but when I do this it goes array index out of bonds. which is understood I am 
> adding i more then the length of array. so how can I generate the series & at 
> the same time save it in an array in the loop.??
>
> sorry for the long question
>
> Sadia Butt

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to