Java PrimeDirective

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

Hi everybody, today I have this message on this exercise…

java PrimeDirective
Error: LinkageError occurred while loading main class PrimeDirective
        java.lang.ClassFormatError: Incompatible magic value 4022320623 in class file PrimeDirective

This is my code until now:

import java.util.ArrayList;

class PrimeDirective {

  

  // Add your methods here:

  public boolean isPrime(int number){

    if(number == 2)

    {

      return true;

    }

    else

    {

      return false;

    }

    for(int i = 2; i < number; i++)

    {

      if(number % i == 0)

      {

        return false;

      }

      return true;

    }

  }

    

  public static void main(String[] args) {

    PrimeDirective pd = new PrimeDirective();

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

    pd.isPrime(7);

  }

 

}

I couldn’t read the class file, it’s appear in weird letters.
I don’t know if its a bug…

Your boolean method isPrime() has a gap in the control flow where it’s unclear to the program whether you will have a proper return.

You also have an unreachable statement in your for-loop because your initial if/else condition will close the method before it gets there.

1 Like

Thank you very much, I forgot the return stament in all my isPrime method… :persevere: