// ---------
// Iota.java
// ---------

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

class Iota implements Iterator<Integer> {
    private int b;
    private int e;
    private int d;

    public Iota (int b, int e, int d) {
        this.b = b;
        this.e = e;
        this.d = d;}

    public boolean hasNext () {
        return b <= e;}

    public Integer next () {
        final int c = b;
        b += d;
        return c;}

    public void remove () {
        throw new UnsupportedOperationException();}}

final class IotaTest {
    public static int accumulate (Iterator<Integer> p) {
        int v = 0;
        while (p.hasNext())
            v += p.next();
        return v;}

    public static void main (String[] args) {
        System.out.println("Iota.java");

        {
        final Collection<Integer> x = Arrays.asList(2, 4, 6, 8, 10);
        assert accumulate(x.iterator()) == 30;
        }

        {
        final Iota i = new Iota(2, 10, 2);
        assert accumulate(i) == 30;
        }

        System.out.println("Done.");}}


syntax highlighted by Code2HTML, v. 0.9.1