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;
                System.out.print("01");
                do {
                        b= a + b;
                        a= b - a;
                        b= a + b -a;
                        System.out.println(+b);
                        count++;
                        }
                while (count>8);
        }
}

Thank you !

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.

yes its works thanks alot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.