Pabl0o0

Untitled

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