Saturday 26 July 2014

Write a Program to Calculate Fibonacci Series using Do-while Loop for Java

public class fibonacci
{
              public static void main(String []args)
              {
                       int pre = 0;
                       int next - 1;
                       int current;
                       System.out.println(pre);
                       System.out.println(next);

                       do  
                      {
                             current = next + pre;
                             System.out.println(current);
                           
                              pre = next;
                              next = current;
                           
                      }
                      while(next<=100);
                 
               }
                  
}

Output

1 comments:

Post a Comment

Followers