Hi every one !

Guys i am trying to do the Fibonacci numbers without an input

just want it to number 8 then stop, But i want to do it using Do While

i did it but , i am missing something i can't find what is it its won't repeat.

i mean the output of this code 01 cuz i print it out but

after that it print only 1, like this 011. why? it won't repeat with count .

class Fp
        public static void main (String args[])
                int a=0;
                int b=1;
                int count=0;
                do {
                        b= a + b;
                        a= b - a;
                        b= a + b -a;
                while (count>8);

Thank you !

6 Years
Discussion Span
Last Post by error.exe.er

If you want 8 numbers, your loop must continue while count is less than 8. In your code it is greater than 8. If you want to print UP TO 8, then you do not necessarily need a count. You could just program it to loop until value of b != 8 . In other worde, while b is not equal to 8.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.