Advertisement
Guest User

Untitled

a guest
Dec 27th, 2021
1,444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Fibonacci {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. ArrayList<Integer> numberList = new ArrayList<Integer>();
  8. numberList.add(0);
  9. numberList.add(1);
  10.  
  11. int indexOne = 0;
  12. int indexTwo = 1;
  13. int sum; // Variable for the sum result of the two values
  14.  
  15. // Output of the first two numbers
  16. System.out.println(numberList.get(0));
  17. System.out.println(numberList.get(1));
  18.  
  19. for (int i = 0; i < 15; i++) {
  20.  
  21. sum = numberList.get(indexOne) + numberList.get(indexTwo);
  22. numberList.add(sum);
  23. indexOne++;
  24. indexTwo++;
  25. System.out.println(sum);
  26.  
  27. }
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement