Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. public class JavaExample {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         int count = 7, num1 = 0, num2 = 1;
  6.         System.out.print("Fibonacci Series of "+count+" numbers:");
  7.  
  8.         for (int i = 1; i <= count; ++i)
  9.         {
  10.             System.out.print(num1+" ");
  11.  
  12.             /* On each iteration, we are assigning second number
  13.              * to the first number and assigning the sum of last two
  14.              * numbers to the second number
  15.              */
  16.             int sumOfPrevTwo = num1 + num2;
  17.             num1 = num2;
  18.             num2 = sumOfPrevTwo;
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement