Pabl0o0

Untitled

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