martinvalchev

Fibonacci

Nov 24th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Fibonacci {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int f1 = 1;
  8.         int f2 = 1;
  9.  
  10.         for (int i = 0; i < n - 1 ; i++) {
  11.             int temp = f1 + f2;
  12.             f1 = f2;
  13.             f2 = temp;
  14.         }
  15.         System.out.println(f2);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment