import structure5.*; public class EvenNumberIterator extends AbstractIterator { private int counter; /* constructor */ public EvenNumberIterator() { reset(); } /* Checks whether there is a next element */ public boolean hasNext() { return true; } /* Resets the iterator to its original state */ public void reset() { counter = 1; } /* Returns the next element without incrementing the counter. */ public Integer get() { return counter * 2; } /* Returns the next element and then increments the counter. */ public Integer next() { int tmp = get(); counter++; return tmp; } public static void main(String[] args) { EvenNumberIterator nums = new EvenNumberIterator(); for (int n : nums) { if (n > 100) break; System.out.println(n); } } }