fork download
  1. import java.util.function.*;
  2. import java.util.stream.*;
  3. import java.util.*;
  4. class Odai13_673 {
  5. static class FibSupplier implements IntSupplier {
  6. private int a, b;
  7. public FibSupplier(int a, int b) {
  8. this.a = a;this.b = b;
  9. }
  10. public int getAsInt() {
  11. int _a = a;a = b;b = _a + b;
  12. return _a;
  13. }
  14. }
  15. public static void p(IntStream s) {
  16. System.out.println(Arrays.toString(s.toArray()));
  17. }
  18. public static IntStream fib(int a, int b) {
  19. return IntStream.generate(new FibSupplier(a, b));
  20. }
  21. public static void main(String[] args) {
  22. p(fib(0, 1).limit(10));
  23. }
  24. }
  25.  
Success #stdin #stdout 0.13s 2184192KB
stdin
Standard input is empty
stdout
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]