fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(getSeries(50));
  13. }
  14.  
  15.  
  16. static ArrayList<Double> getSeries(int n)
  17. {
  18. ArrayList<Double> series = new ArrayList<>();
  19. series.add(0.0); // This is working as replacement of the F(0)
  20. series.add(1.0); // This is working as replacement of the F(1)
  21. double x, y;
  22.  
  23. for (int i = 1; i < n; i++)
  24. {
  25. x = series.get(i - 1); // This is working as replacement of the F(n-2)
  26. y = series.get(i); // This is working as replacement of the F(n-1)
  27. series.add(x + y);
  28. }
  29.  
  30. return series;
  31. }
  32.  
  33.  
  34. }
Success #stdin #stdout 0.06s 27876KB
stdin
Standard input is empty
stdout
[0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0, 55.0, 89.0, 144.0, 233.0, 377.0, 610.0, 987.0, 1597.0, 2584.0, 4181.0, 6765.0, 10946.0, 17711.0, 28657.0, 46368.0, 75025.0, 121393.0, 196418.0, 317811.0, 514229.0, 832040.0, 1346269.0, 2178309.0, 3524578.0, 5702887.0, 9227465.0, 1.4930352E7, 2.4157817E7, 3.9088169E7, 6.3245986E7, 1.02334155E8, 1.65580141E8, 2.67914296E8, 4.33494437E8, 7.01408733E8, 1.13490317E9, 1.836311903E9, 2.971215073E9, 4.807526976E9, 7.778742049E9, 1.2586269025E10]