Advertisement
Azazavr

Алгоритм Фибоначчи

Feb 20th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. public class Fibonacci {
  2.     public static void main(String[] args) {
  3.  
  4.         int n = 2;
  5.         int fn=0;
  6.         int fnMinus1 = 1;
  7.         int fnMinus2 = 1;
  8.         int nMax = 8;
  9.  
  10.         while (n < nMax){
  11.             fn = fnMinus1+fnMinus2;
  12.             System.out.print(fn + " ");
  13.             fnMinus2=fnMinus1;
  14.             fnMinus1 = fn;
  15.             n++;
  16.  
  17.         }
  18.  
  19.         }
  20.  
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement