Advertisement
veronikaaa86

Fibonacci

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