class Primes { field int first constructor() this.first := 2 constructor(int first) this.first := first method int getHead() return this.first method Primes getTail() { int next := this.first + 1; while (!this.isPrime(next)) next := next + 1; return new Primes(next) } method boolean isPrime(int n) { int divisore := 2; while (divisore < n) if (n / divisore * divisore = n) then return false else divisore := divisore + 1; return true } method void main() { Primes p := new Primes(); for (int count := 1; count <= 100; count := count + 1) { "".concat(p.getHead()).concat(" ").output(); p := p.getTail() } } }