Pabl0o0

Untitled

Oct 29th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class Main {
  2.  
  3. static Scanner sc = new Scanner(System.in);
  4.  
  5.  
  6. public static int Fibonacci(int a, int n){
  7.  
  8. int b = a+1;
  9. for (int i = 0; i < n; i++)
  10. {
  11. int temp = a;
  12. a = b;
  13. b = temp + b;
  14. }
  15. return a;
  16.  
  17.  
  18. }
  19.  
  20. public static void main(String[] args) {
  21. int n;
  22. System.out.println("Podaj liczbę n: ");
  23. n = sc.nextInt();
  24.  
  25. int a;
  26. System.out.println("Podaj liczbę a: ");
  27. a = sc.nextInt();
  28. for (int i = 0; i < n; i++)
  29. {
  30. System.out.println(Fibonacci(a,i));
  31. }
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment