Java: PrimeDirective, all true results on Step 8

I’m on step 8 for Java’s PrimeDirective. When I run the code, I get all true back. I’ve tried moving the return true statement. I’ve also tried adding an else if statement that says if number % i !== 0, return true. Not sure where to go next with this.

public boolean isPrime(int number) {

if (number == 2) {

 return true;

} else if (number < 2) {

 return false;

}

for (int i = 2; i > number; i++) {

if (number % i == 0) {

 return false;

} 

} return true;

}

1 Like

Hi,

You’re very close to getting what you want. I would just revise your for-loop declaration (test that it even runs with some println statements).

1 Like

Hey @brittanynichols72660 it’s been a little while since you originally posted this question. Could you come back to let us know if the above reply helped you?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.