Dremendo Tag Line

Print the fibonacci number series 1 1 2 3 5 using while loop in Java

while Loop - Question 7

In this question, we will see how to print the fibonacci number series 1 1 2 3 5 8... up to 10th term in Java programming using while loop. To know more about while loop click on the while loop lesson.

Q7) Write a program in Java to print the fibonacci number series given below using while loop.

1 1 2 3 5 8... up to 10th term

Program

public class Q7
{
    public static void main(String args[])
    {
        int i=1,n1=1,n2=0,n3;

        while(i<=10)
        {
            n3=n1+n2;
            System.out.print(n3 + " ");
            n1=n2;
            n2=n3;

            i=i+1;
        }
    }
}

Output

1 1 2 3 5 8 13 21 34 55
video-poster