Java method to print prime numbers from specific range
<p>I'm trying to make a method to copy all prime numbers from a specific range (provided by a constructor (int lowerBound, int upperBound) using these methods , can't seem to have much success. Can anyone help?</p>

<p>public class PrimesEnumerator {</p>

<pre><code>int upperBound;
int lowerBound;
int count = 0;
boolean b;
int num=0;

public PrimesEnumerator(int upperBound) {
    this.upperBound = upperBound;
    this.lowerBound = 2;
}

public PrimesEnumerator(int lowerBound, int upperBound) {
    this.upperBound = upperBound;
    this.lowerBound = lowerBound;
    String str = num + ", ";
    while (hasNext()) {
        str += str;
        lowerBound = num;
        next();
        System.out.println(str);
    }


}

public static boolean isPrime(int number)
    {
    if (number ==1)
        return false;
    for(int i = 2; i * i &lt;= number; i++)
         if(number % i == 0)
         return false;
    return true;
    }

public boolean hasNext() {

    for (int j = lowerBound; j&lt;=upperBound;j++)
    {
        if (isPrime(j)) {
            num=j;
            return true;
        }
        b = false;
    }
    return b;
}

public int next() {
    if (hasNext()) {
        return num;
    }
    else return(0);
}
</code></pre>

<p>}</p>
