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. for (int i : new Seii(2, 42)) {
  13. System.out.println(i);
  14. }
  15. }
  16. }
  17.  
  18. class Seii implements Iterable<Integer> {
  19. private int current;
  20. private int max;
  21. public Seii(int current, int max) {
  22. this.current = current;
  23. this.max = max;
  24. }
  25. @Override
  26. public Iterator<Integer> iterator() {
  27. return new SeiIterator(current, max);
  28. }
  29. }
  30.  
  31. class SeiIterator implements Iterator<Integer> {
  32. private int current;
  33. private int max;
  34. public SeiIterator(int current, int max) {
  35. this.current = current;
  36. this.max = max;
  37. }
  38. @Override
  39. public boolean hasNext() {
  40. return current < max;
  41. }
  42. @Override
  43. public Integer next() {
  44. current = (3*current)/2;
  45. return current;
  46. }
  47. @Override
  48. public void remove() {
  49. }
  50. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
3
4
6
9
13
19
28
42