Advertisement
galinyotsev123

ProgBasicsJavaBook7.1ComplexLoop14fibonacci

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