I have been trying for a few hours now to implement the next () method of the Iterator interface, with the aim of returning the next prime number
The constructor receives an argument that specifies the limit of the maximum prime number. For example, Prime Iterator (100) creates an object that iterates prime numbers less than or equal to 100.
@Override
public Integer next() {
Integer contador = limite;
Integer num = 0;
for(int i=0;i<contador && esPrimo(num)==false;i++)
num+=i;
return num;
}
This is one of the codes that has occurred to me but I only get the value that has num at the beginning, that is, zero. Thanks for the answers