PrimeDirective project - can't find my error? [SOLVED]

Hi, first time posting so hopefully I get this right. Total newbie to Java before this course. I’m stuck on step 8 of the PrimeDirective project. (https://www.codecademy.com/courses/learn-java/projects/java-prime-directive)

I think I’ve followed all the instructions carefully and have spent a couple hours going over and over it but can’t find my error. When I try to compile I get this message: PrimeDirective.java:22:error missing return statement. But I do have return statements. Do I just have something misplaced? Here’s my code so far:

import java.util.ArrayList;

class PrimeDirective{

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;

} else {

  return true;     

  }

}
}

public static void main(String args) {

PrimeDirective pd = new PrimeDirective();

int[] numbers = {6, 29, 28, 33, 11, 100, 101, 43, 89};

}

}

Thanks for any help!

OK, no idea why parts of this message are in grey blocks…I copied and pasted it all as one unit. Sorry.

I figured out that part just now finally - I had a “return true” statement outside the method instead of inside the method. I can’t figure out how to delete this post, however.

1 Like