Advertisement
tchenkov

L07u12_Fibonacci

Feb 21st, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package Uprajneniq;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by todor on 21.02.2017 г..
  7.  */
  8. public class u12_Fibonacci {
  9.     public static void main(String[] args) {
  10.         Scanner scan = new Scanner(System.in);
  11.         int fibonacciNumberIndex = Integer.parseInt(scan.nextLine());
  12.        
  13.         int fib0 = 1;
  14.         int fib1 = 1;
  15.         for (int i = 2; i <= fibonacciNumberIndex; i++) {
  16.             int currentFib = fib0 + fib1;
  17.             fib0 = fib1;
  18.             fib1 = currentFib;
  19.         }
  20.    
  21.         System.out.println(fib1);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement