PrimeDirective.java

// Import statement:

import java.util.ArrayList;

class PrimeDirective {

// Add your methods here:

public Boolean isPrime(int number){

if (number == 2){

    return true;

  }else if(number < 2){

    return false;

  }

for(int n = 2; n <= number; n++) {

   if(number % n == 0){

     return true;

    }

}

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(7));

    System.out.println(pd.isPrime(28));

    System.out.println(pd.isPrime(2));

    System.out.println(pd.isPrime(0)); 

    

    }  

}


compiler says:

true
t
t
false

why i get true for 28 ? can s.o. help =)

1 Like

Try adding print statements when you have 28 to look at how your conditionals are working, there’s a good chance you’ll notice where the issue is :slight_smile:

Think about: where is the code that is essential to say that 28 is prime? You’ll need print statements there.

1 Like

Hello, @byte2390130468, and welcome to the forums.

I only see one place in your method that returns false.

I don’t think 28 is less than 2.

1 Like

thanks now i have the rigth solution =)

1 Like