The Prime Directive Project error

I am stuck on one of the steps in the Prime Directive Project. I feel that I have followed the instructions exactly. Can someone please help me with the “missing return statement error” I am getting here?


import java.util.ArrayList;

class PrimeDirective {
  
  public boolean isPrime(int number) {

    if (number == 2){
    return true;

    }else if (number < 2){
    return false;
    }else{
    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};

    System.out.println(pd.isPrime(6));
  }  

}

1 Like

Hello @ohene-danquah, is there any error being thrown? Do you have a specific question?

@chriswietfeldt580844 I feel you, let me try to help you on how I solved it, let’s see:

forget what internet told you about a prime number is divisible by itself, by 1, etc…

here’s the clue:

  • a prime number is the result of → multiplying a number times 1 ( “n” * 1 )
  • other than “n” or 1 multiplied, its product cannot result in “n”
    and
  • aren’t decimals

in other words, you can only get 5 by ( 5 * 1 ), or 101 by ( 101 * 1 )
no other ( number * number ) can produce the 5 or 101, besides “n” * 1

example: 7 ( prime )

7 * 1 = 7

2 * 3 = 6 ( not 7 )
2 * 4 = 8 ( not 7 )

example: 8 ( not prime )

8 * 1 = 8

2 * 4 = 8 ( we got 8 using other numbers than 8 or 1 )

other rules

  • number 0 cannot be prime because is nothing, and can’t be anything, not even a decimal, it’s only a representational digit of void.
  • number 1 neither considered as it only has 1 divisor, unlike 2 → 2/1 or 2/2

now, try to create an algoritm that does the rules i suggest, if you still have trouble, I guess you will receive help by me or others as well.