Advertisement
huubinh49

printFibonanci

Feb 14th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. public class test
  2. {
  3.     public static void printFibo(int n)
  4.     {
  5.         int a[]=new int[2];
  6.         a[0]=a[1]=1;
  7.         int i=2;
  8.         for(;i<n;i++)
  9.         {
  10.             a[i%2]=a[0]+a[1];
  11.         }
  12.         System.out.print(a[(i-1)%2]);
  13.     }
  14.     public static void main(String arg[])
  15.     {
  16.         printFibo(3);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement