Untitled

 avatar
unknown
java
3 years ago
1.4 kB
6
Indexable
import java.util.Iterator;

public class Primi implements Iterator  {
    
private int quanti; 
private int curr;
private int count;

    //costruttore default
    public Primi() {        
    this.curr = 2;

    }

 //costuttore con parametri 
    public Primi(int quanti, int curr) throws IllegalArgumentException {
    if (quanti <0) throw new IllegalArgumentException("metti un numero positivo") ;
    
    for (int index = 0; index < quanti; index++) {
        
    
        for (int divisore = 2; divisore < curr; divisore++) {
            if (curr%divisore == 0 ) {
                curr++;
            } else {
                this.curr= curr;
                count++;
            }
        }
         
    }

    

    }


    

    @Override
    public boolean hasNext() {
        // return true if iterator has more elements to iterate. 
        // in this case true until reached the number in args[0]
        if (count < quanti) return true;
        
        return false;
    }

    @Override
    public Object next() {
        // returns the next element in the collection until the hasNext()method return true. 
        // in this case next elements are prime numbers

        
        
    }



    public static void main(String[] args) {
        int quanti = Integer.parseInt( args[0]);
       

    }
}
Editor is loading...