Advertisement
Ivakis

Fibonacci

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