Prime directive

I am stuck on step 8 of the prime directive (https://www.codecademy.com/courses/learn-java/projects/java-prime-directive). There is an error in my code but I cannot figure out what the error is. Please help.

error i get when trying to compile:
PrimeDirective.java:20: error: missing return statement
}
^

My code:

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};
  }  
}

What does return do and what value does i have by the time you execute return for number=25? Are you done determining whether 25 is prime at that point?

The project is supposed to find prime numbers. Step 8 tells you to test your code. I get that error when i go to compile.

Step 8 says:
Test out your isPrime() method on pd in main() and see if it works!

Try it out with a few numbers:

  • 7 should return true
  • 28 should return false
  • 2 should return true
  • 0 should return false

Don’t forget to run your code with the following:

I mean, take your index finger, or any finger good for pointing. Point at the top of the function. Set number to 25. move your finger downwards as you execute each instruction.

Your error message is about that all paths through your method need to end in a return statement.

But your mistake is that the logic is wrong.

hmm, okay thank you for the help

Figured it out. Thanks for the advice! I had been stuck on that for days.