Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

public int next() { for (int i=lowerRange; i<=upper; i++) { if (lowerRange>upper) { break; } if (isPrime(i)==true) { lowerRange=i+1; return i; } } return 0; } For some reason this is giving me the prime numbers up until the "upper"-th prime number, instead of all the prime numbers until the VALUE OF upper. Any ideas??

OpenStudy (rsmith6559):

I think you've stumbled onto an oddity of variable scoping. i inside the braces is one thing, i in the for loop is another. Just for fun, put a print statement in the second if block and see what happens on a short run.

OpenStudy (anonymous):

I didn't get what do you want to archive with this function. Is your objective to list all prime number from a number X to a number Y?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!